<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  

  
  <title>Threadv</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <meta property="og:type" content="website">
<meta property="og:title" content="Threadv">
<meta property="og:url" content="http://yoursite.com/page/6/index.html">
<meta property="og:site_name" content="Threadv">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Threadv">
  
    <link rel="alternate" href="/atom.xml" title="Threadv" type="application/atom+xml">
  
  
    <link rel="icon" href="/favicon.png">
  
  
    <link href="//fonts.googleapis.com/css?family=Source+Code+Pro" rel="stylesheet" type="text/css">
  
  <link rel="stylesheet" href="/css/style.css">
</head>

<body>
  <div id="container">
    <div id="wrap">
      <header id="header">
  <div id="banner"></div>
  <div id="header-outer" class="outer">
    <div id="header-title" class="inner">
      <h1 id="logo-wrap">
        <a href="/" id="logo">Threadv</a>
      </h1>
      
    </div>
    <div id="header-inner" class="inner">
      <nav id="main-nav">
        <a id="main-nav-toggle" class="nav-icon"></a>
        
          <a class="main-nav-link" href="/">Home</a>
        
          <a class="main-nav-link" href="/archives">Archives</a>
        
      </nav>
      <nav id="sub-nav">
        
          <a id="nav-rss-link" class="nav-icon" href="/atom.xml" title="RSS Feed"></a>
        
        <a id="nav-search-btn" class="nav-icon" title="Suche"></a>
      </nav>
      <div id="search-form-wrap">
        <form action="//google.com/search" method="get" accept-charset="UTF-8" class="search-form"><input type="search" name="q" class="search-form-input" placeholder="Search"><button type="submit" class="search-form-submit">&#xF002;</button><input type="hidden" name="sitesearch" value="http://yoursite.com"></form>
      </div>
    </div>
  </div>
</header>
      <div class="outer">
        <section id="main">
  
    <article id="post-WXPayConfig" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-meta">
    <a href="/2018/12/07/WXPayConfig/" class="article-date">
  <time datetime="2018-12-07T02:58:35.000Z" itemprop="datePublished">2018-12-07</time>
</a>
    
  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 itemprop="name">
      <a class="article-title" href="/2018/12/07/WXPayConfig/">WXPayConfig</a>
    </h1>
  

      </header>
    
    <div class="article-entry" itemprop="articleBody">
      
        <h5 id="WXPayConfig"><a href="#WXPayConfig" class="headerlink" title="WXPayConfig"></a>WXPayConfig</h5><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> com.ifenghui.storybookapi.util.weixin;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> java.io.ByteArrayInputStream;</span><br><span class="line"><span class="keyword">import</span> java.io.File;</span><br><span class="line"><span class="keyword">import</span> java.io.FileInputStream;</span><br><span class="line"><span class="keyword">import</span> java.io.InputStream;</span><br><span class="line"></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">WXPayConfigImpl</span> <span class="keyword">extends</span> <span class="title">WXPayConfig</span> </span>&#123;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">private</span> String appId;</span><br><span class="line">    <span class="keyword">private</span> String mchId;</span><br><span class="line">    <span class="keyword">private</span> <span class="keyword">byte</span>[] certData;</span><br><span class="line">    <span class="keyword">private</span> <span class="keyword">static</span> WXPayConfigImpl INSTANCE;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">private</span> <span class="title">WXPayConfigImpl</span><span class="params">(String certpath, String appId, String mchId)</span> <span class="keyword">throws</span> Exception </span>&#123;</span><br><span class="line">        <span class="keyword">this</span>.appId = appId;</span><br><span class="line">        <span class="keyword">this</span>.mchId = mchId;</span><br><span class="line"><span class="comment">//        String certPath = "C:\\Users\\Administrator\\Desktop\\cert故事飞船商户号微信证书\\apiclient_cert.p12";</span></span><br><span class="line">        String certPath = certpath;</span><br><span class="line"></span><br><span class="line">        File file = <span class="keyword">new</span> File(certPath);</span><br><span class="line">        InputStream certStream = <span class="keyword">new</span> FileInputStream(file);</span><br><span class="line">        <span class="keyword">this</span>.certData = <span class="keyword">new</span> <span class="keyword">byte</span>[(<span class="keyword">int</span>) file.length()];</span><br><span class="line">        certStream.read(<span class="keyword">this</span>.certData);</span><br><span class="line">        certStream.close();</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> WXPayConfigImpl <span class="title">getInstance</span><span class="params">(String certpath, String appId, String mchId)</span> <span class="keyword">throws</span> Exception </span>&#123;</span><br><span class="line">        <span class="keyword">if</span> (INSTANCE == <span class="keyword">null</span>) &#123;</span><br><span class="line">            <span class="keyword">synchronized</span> (WXPayConfigImpl.class) &#123;</span><br><span class="line">                <span class="keyword">if</span> (INSTANCE == <span class="keyword">null</span>) &#123;</span><br><span class="line">                    INSTANCE = <span class="keyword">new</span> WXPayConfigImpl(certpath, appId, mchId);</span><br><span class="line">                &#125;</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">return</span> INSTANCE;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">    <span class="meta">@Override</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> String <span class="title">getAppID</span><span class="params">()</span> </span>&#123;</span><br><span class="line">        <span class="keyword">return</span> <span class="keyword">this</span>.appId;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@Override</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> String <span class="title">getMchID</span><span class="params">()</span> </span>&#123;</span><br><span class="line">        <span class="keyword">return</span> <span class="keyword">this</span>.mchId;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">    <span class="meta">@Override</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> String <span class="title">getKey</span><span class="params">()</span> </span>&#123;</span><br><span class="line">        <span class="keyword">return</span> <span class="string">"xxxxxxxxxxxxxxxxxxxxxx"</span>;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@Override</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> InputStream <span class="title">getCertStream</span><span class="params">()</span> </span>&#123;</span><br><span class="line">        ByteArrayInputStream certBis;</span><br><span class="line">        certBis = <span class="keyword">new</span> ByteArrayInputStream(<span class="keyword">this</span>.certData);</span><br><span class="line">        <span class="keyword">return</span> certBis;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">    <span class="meta">@Override</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">int</span> <span class="title">getHttpConnectTimeoutMs</span><span class="params">()</span> </span>&#123;</span><br><span class="line">        <span class="keyword">return</span> <span class="number">2000</span>;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@Override</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">int</span> <span class="title">getHttpReadTimeoutMs</span><span class="params">()</span> </span>&#123;</span><br><span class="line">        <span class="keyword">return</span> <span class="number">10000</span>;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@Override</span></span><br><span class="line">    <span class="function">IWXPayDomain <span class="title">getWXPayDomain</span><span class="params">()</span> </span>&#123;</span><br><span class="line">        <span class="keyword">return</span> WXPayDomainSimpleImpl.instance();</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">public</span> String <span class="title">getPrimaryDomain</span><span class="params">()</span> </span>&#123;</span><br><span class="line">        <span class="keyword">return</span> <span class="string">"api.mch.weixin.qq.com"</span>;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">public</span> String <span class="title">getAlternateDomain</span><span class="params">()</span> </span>&#123;</span><br><span class="line">        <span class="keyword">return</span> <span class="string">"api2.mch.weixin.qq.com"</span>;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@Override</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">int</span> <span class="title">getReportWorkerNum</span><span class="params">()</span> </span>&#123;</span><br><span class="line">        <span class="keyword">return</span> <span class="number">1</span>;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@Override</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">int</span> <span class="title">getReportBatchSize</span><span class="params">()</span> </span>&#123;</span><br><span class="line">        <span class="keyword">return</span> <span class="number">2</span>;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> com.ifenghui.storybookapi.util.weixin;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> java.io.InputStream;</span><br><span class="line"></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">abstract</span> <span class="class"><span class="keyword">class</span> <span class="title">WXPayConfig</span> </span>&#123;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"></span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * 获取 App ID</span></span><br><span class="line"><span class="comment">     *</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@return</span> App ID</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="function"><span class="keyword">abstract</span> String <span class="title">getAppID</span><span class="params">()</span></span>;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * 获取 Mch ID</span></span><br><span class="line"><span class="comment">     *</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@return</span> Mch ID</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="function"><span class="keyword">abstract</span> String <span class="title">getMchID</span><span class="params">()</span></span>;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * 获取 API 密钥</span></span><br><span class="line"><span class="comment">     *</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@return</span> API密钥</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="function"><span class="keyword">abstract</span> String <span class="title">getKey</span><span class="params">()</span></span>;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * 获取商户证书内容</span></span><br><span class="line"><span class="comment">     *</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@return</span> 商户证书内容</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="function"><span class="keyword">abstract</span> InputStream <span class="title">getCertStream</span><span class="params">()</span></span>;</span><br><span class="line"></span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * HTTP(S) 连接超时时间，单位毫秒</span></span><br><span class="line"><span class="comment">     *</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@return</span></span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">int</span> <span class="title">getHttpConnectTimeoutMs</span><span class="params">()</span> </span>&#123;</span><br><span class="line">        <span class="keyword">return</span> <span class="number">6</span>*<span class="number">1000</span>;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * HTTP(S) 读数据超时时间，单位毫秒</span></span><br><span class="line"><span class="comment">     *</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@return</span></span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">int</span> <span class="title">getHttpReadTimeoutMs</span><span class="params">()</span> </span>&#123;</span><br><span class="line">        <span class="keyword">return</span> <span class="number">8</span>*<span class="number">1000</span>;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * 获取WXPayDomain, 用于多域名容灾自动切换</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@return</span></span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="function"><span class="keyword">abstract</span> IWXPayDomain <span class="title">getWXPayDomain</span><span class="params">()</span></span>;</span><br><span class="line"></span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * 是否自动上报。</span></span><br><span class="line"><span class="comment">     * 若要关闭自动上报，子类中实现该函数返回 false 即可。</span></span><br><span class="line"><span class="comment">     *</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@return</span></span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">boolean</span> <span class="title">shouldAutoReport</span><span class="params">()</span> </span>&#123;</span><br><span class="line">        <span class="keyword">return</span> <span class="keyword">true</span>;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * 进行健康上报的线程的数量</span></span><br><span class="line"><span class="comment">     *</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@return</span></span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">int</span> <span class="title">getReportWorkerNum</span><span class="params">()</span> </span>&#123;</span><br><span class="line">        <span class="keyword">return</span> <span class="number">6</span>;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * 健康上报缓存消息的最大数量。会有线程去独立上报</span></span><br><span class="line"><span class="comment">     * 粗略计算：加入一条消息200B，10000消息占用空间 2000 KB，约为2MB，可以接受</span></span><br><span class="line"><span class="comment">     *</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@return</span></span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">int</span> <span class="title">getReportQueueMaxSize</span><span class="params">()</span> </span>&#123;</span><br><span class="line">        <span class="keyword">return</span> <span class="number">10000</span>;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * 批量上报，一次最多上报多个数据</span></span><br><span class="line"><span class="comment">     *</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@return</span></span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">int</span> <span class="title">getReportBatchSize</span><span class="params">()</span> </span>&#123;</span><br><span class="line">        <span class="keyword">return</span> <span class="number">10</span>;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
      
    </div>
    <footer class="article-footer">
      <a data-url="http://yoursite.com/2018/12/07/WXPayConfig/" data-id="ckcc5iwjj0015q4uw0i1jcs1z" class="article-share-link">Teilen</a>
      
      
  <ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/util/">util</a></li></ul>

    </footer>
  </div>
  
</article>


  
    <article id="post-pay_wx 转账退款" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-meta">
    <a href="/2018/12/07/pay_wx 转账退款/" class="article-date">
  <time datetime="2018-12-07T02:57:34.000Z" itemprop="datePublished">2018-12-07</time>
</a>
    
  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 itemprop="name">
      <a class="article-title" href="/2018/12/07/pay_wx 转账退款/">wx 转账退款</a>
    </h1>
  

      </header>
    
    <div class="article-entry" itemprop="articleBody">
      
        <h5 id="wx-转账退款"><a href="#wx-转账退款" class="headerlink" title="wx 转账退款"></a>wx 转账退款</h5><ul>
<li>创建提现申请</li>
</ul>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line">CashAccountCashApply cashAccountCashApply = <span class="keyword">new</span> CashAccountCashApply();</span><br><span class="line">cashAccountCashApply.setIntro(<span class="string">""</span>);</span><br><span class="line">cashAccountCashApply.setAmount(amount);</span><br><span class="line">cashAccountCashApply.setStatus(<span class="number">1</span>);</span><br><span class="line">cashAccountCashApply.setCallbackStatus(<span class="number">0</span>);</span><br><span class="line">cashAccountCashApply.setResultStatus(<span class="number">0</span>);</span><br><span class="line">cashAccountCashApply.setType(cashAccountApplyStyle);</span><br><span class="line">cashAccountCashApply.setUserId(userId);</span><br><span class="line">cashAccountCashApply.setOrderId(<span class="string">""</span>);</span><br><span class="line"><span class="comment">//微信用户openid</span></span><br><span class="line">cashAccountCashApply.setAccount(account);</span><br><span class="line">cashAccountCashApply.setCallbackMsg(<span class="string">""</span>);</span><br><span class="line">cashAccountCashApply.setUserInfo(userInfo);</span><br><span class="line">cashAccountCashApply.setCreateTime(<span class="keyword">new</span> Date());</span><br><span class="line">cashAccountCashApply.setSuccessTime(<span class="keyword">new</span> Date());</span><br><span class="line">cashAccountCashApplyDao.save(cashAccountCashApply);</span><br></pre></td></tr></table></figure>
<ul>
<li>处理微信提现退款<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">dealWechatPayRefund</span><span class="params">(CashAccountCashApply cashAccountCashApply)</span> <span class="keyword">throws</span> Exception </span>&#123;</span><br><span class="line">    Map&lt;String, String&gt; response = <span class="keyword">this</span>.wechatPayTransfer(cashAccountCashApply);</span><br><span class="line">    String prefix = env.getProperty(<span class="string">"cash.transfer.prefix"</span>);</span><br><span class="line">    logger.info(<span class="string">"==========微信回调数据============"</span>);</span><br><span class="line">    logger.info(<span class="string">"=========prefix ="</span>+prefix+<span class="string">"============"</span>);</span><br><span class="line">    String orderStr = prefix + cashAccountCashApply.getId();</span><br><span class="line">    String partnerTradeNo = response.get(<span class="string">"partner_trade_no"</span>);</span><br><span class="line">    ObjectMapper objectMapper = <span class="keyword">new</span> ObjectMapper();</span><br><span class="line">    String resultCode = response.get(<span class="string">"return_code"</span>);</span><br><span class="line">    String responseString = <span class="string">"默认转账响应（问题）！"</span>;</span><br><span class="line">    logger.info(<span class="string">"==========默认转账响应（问题）============"</span>);</span><br><span class="line">    <span class="keyword">try</span> &#123;</span><br><span class="line">        responseString = objectMapper.writeValueAsString(response);</span><br><span class="line">        logger.info(<span class="string">"==========微信回调数据============"</span>);</span><br><span class="line">        logger.info(responseString);</span><br><span class="line">    &#125; <span class="keyword">catch</span> (JsonProcessingException je) &#123;</span><br><span class="line">        <span class="keyword">throw</span> <span class="keyword">new</span> RuntimeException(<span class="string">"wechat pay refund json serialize error!"</span>);</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">if</span> (resultCode.equals(<span class="string">"SUCCESS"</span>) &amp;&amp; orderStr.equals(partnerTradeNo)) &#123;</span><br><span class="line">        logger.info(<span class="string">"=========状态更改============="</span>);</span><br><span class="line">        logger.info(resultCode);</span><br><span class="line"></span><br><span class="line">        <span class="keyword">this</span>.changeCashAccountApplyStatus(</span><br><span class="line">                cashAccountCashApply,</span><br><span class="line">                responseString,</span><br><span class="line">                CashAccountApplyStatusStyle.SUCCESS_FINISH, <span class="number">1</span>, <span class="number">1</span>);</span><br><span class="line">    &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">        logger.info(<span class="string">"=========状态更改============="</span>);</span><br><span class="line">        logger.info(resultCode);</span><br><span class="line">        <span class="keyword">this</span>.changeCashAccountApplyStatus(</span><br><span class="line">                cashAccountCashApply,</span><br><span class="line">                responseString,</span><br><span class="line">                CashAccountApplyStatusStyle.WAIT_PAY_CASH, <span class="number">2</span>, <span class="number">0</span>);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
</li>
</ul>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">private</span> Map&lt;String, String&gt; <span class="title">wechatPayTransfer</span><span class="params">(CashAccountCashApply cashAccountCashApply)</span> <span class="keyword">throws</span> Exception </span>&#123;</span><br><span class="line">        logger.info(<span class="string">"-----微信提现---"</span>);</span><br><span class="line"></span><br><span class="line">        <span class="keyword">try</span> &#123;</span><br><span class="line">            <span class="comment">//证书地址</span></span><br><span class="line">            String certpath = env.getProperty(<span class="string">"certPath"</span>);</span><br><span class="line">            logger.info(<span class="string">"======="</span> + certpath + <span class="string">"======"</span>);</span><br><span class="line">            String appId = env.getProperty(<span class="string">"appid"</span>);</span><br><span class="line">            logger.info(<span class="string">"======="</span> + appId + <span class="string">"======"</span>);</span><br><span class="line">            String mchId = env.getProperty(<span class="string">"mch_id"</span>);</span><br><span class="line">            logger.info(<span class="string">"======="</span> + mchId + <span class="string">"======"</span>);</span><br><span class="line">            </span><br><span class="line">            <span class="comment">//appid不一样通过wxconfig在内部赋值 util标签</span></span><br><span class="line">            WxConfig = WXPayConfigImpl.getInstance(certpath, appId, mchId);</span><br><span class="line">            wxpay = <span class="keyword">new</span> WXPay(WxConfig);</span><br><span class="line">        &#125; <span class="keyword">catch</span> (Exception e) &#123;</span><br><span class="line">            e.printStackTrace();</span><br><span class="line">        &#125;</span><br><span class="line">        String prefix = env.getProperty(<span class="string">"cash.transfer.prefix"</span>);</span><br><span class="line">        logger.info(<span class="string">"----------"</span> + prefix + <span class="string">"---------"</span>);</span><br><span class="line">        logger.info(<span class="string">"---------获取ip----------"</span>);</span><br><span class="line">        String ip = <span class="string">""</span>;</span><br><span class="line">        <span class="keyword">try</span> &#123;</span><br><span class="line">            ip = HttpRequest.getIpAddr(request);</span><br><span class="line">        &#125; <span class="keyword">catch</span> (Exception e) &#123;</span><br><span class="line">            <span class="comment">//本地测试直接写ip</span></span><br><span class="line">            ip = <span class="string">"124.xxx.xx.xx"</span>;</span><br><span class="line">        &#125;</span><br><span class="line">        logger.info(<span class="string">"-----ip : "</span> + ip + <span class="string">"---"</span>);</span><br><span class="line">        String orderStr = prefix + cashAccountCashApply.getId();</span><br><span class="line">        Integer amount = cashAccountCashApply.getAmount();</span><br><span class="line">        logger.info(<span class="string">"-----amount : "</span> + amount + <span class="string">"---"</span>);</span><br><span class="line">        HashMap&lt;String, String&gt; data = <span class="keyword">new</span> HashMap&lt;String, String&gt;();</span><br><span class="line">        data.put(<span class="string">"mch_appid"</span>, <span class="string">"wxxxxxxxxxx"</span>);</span><br><span class="line">        data.put(<span class="string">"mchid"</span>, <span class="string">"14xxxxxx"</span>);</span><br><span class="line">        data.put(<span class="string">"amount"</span>, amount.toString());</span><br><span class="line">        data.put(<span class="string">"check_name"</span>, <span class="string">"NO_CHECK"</span>);</span><br><span class="line">        data.put(<span class="string">"desc"</span>, <span class="string">"xxx提现(退款)"</span>);</span><br><span class="line">        <span class="comment">//随机字符串 util标签工具类中有</span></span><br><span class="line">        data.put(<span class="string">"nonce_str"</span>, WXPayUtil.generateUUID());</span><br><span class="line">        data.put(<span class="string">"openid"</span>, cashAccountCashApply.getAccount());</span><br><span class="line">        data.put(<span class="string">"partner_trade_no"</span>, orderStr);</span><br><span class="line">        data.put(<span class="string">"spbill_create_ip"</span>, ip);</span><br><span class="line">        </span><br><span class="line">        <span class="comment">//可直接调用返回 如下处理是因为key不一样自己处理</span></span><br><span class="line"><span class="comment">//        Map&lt;String, String&gt; response = wxpay.transfers(data);</span></span><br><span class="line"></span><br><span class="line">        <span class="comment">//公众号的key</span></span><br><span class="line">        String sign = WXPayUtil.generateSignature(data, <span class="string">"xxxxxxxxxxxxx"</span>);</span><br><span class="line">        data.put(<span class="string">"sign"</span>, sign);</span><br><span class="line"></span><br><span class="line">        logger.info(<span class="string">"-----sign : "</span> + sign + <span class="string">"---"</span>);</span><br><span class="line"></span><br><span class="line">        String res = wxpay.requestWithCert(<span class="string">"/mmpaymkttransfers/promotion/transfers"</span>, (Map&lt;String, String&gt;) data, <span class="keyword">this</span>.WxConfig.getHttpConnectTimeoutMs(), <span class="keyword">this</span>.WxConfig.getHttpReadTimeoutMs());</span><br><span class="line"></span><br><span class="line">        logger.info(<span class="string">"-----res : "</span> + res + <span class="string">"---"</span>);</span><br><span class="line">        <span class="comment">//直接转map</span></span><br><span class="line">        Map&lt;String, String&gt; response = WXPayUtil.xmlToMap(res);</span><br><span class="line">        logger.info(<span class="string">"=============response=============="</span>);</span><br><span class="line">        <span class="keyword">return</span> response;</span><br><span class="line">    &#125;</span><br></pre></td></tr></table></figure>
      
    </div>
    <footer class="article-footer">
      <a data-url="http://yoursite.com/2018/12/07/pay_wx 转账退款/" data-id="ckcc5iwl7002uq4uwehm3rt8f" class="article-share-link">Teilen</a>
      
      
  <ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/ali-weixin-pay/">ali/weixin pay</a></li></ul>

    </footer>
  </div>
  
</article>


  
    <article id="post-pay_ali 转账退款" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-meta">
    <a href="/2018/12/07/pay_ali 转账退款/" class="article-date">
  <time datetime="2018-12-07T02:57:33.000Z" itemprop="datePublished">2018-12-07</time>
</a>
    
  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 itemprop="name">
      <a class="article-title" href="/2018/12/07/pay_ali 转账退款/">ali 转账退款</a>
    </h1>
  

      </header>
    
    <div class="article-entry" itemprop="articleBody">
      
        <h5 id="ali-转账退款"><a href="#ali-转账退款" class="headerlink" title="ali 转账退款"></a>ali 转账退款</h5><ul>
<li>创建提现申请</li>
</ul>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line">CashAccountCashApply cashAccountCashApply = <span class="keyword">new</span> CashAccountCashApply();</span><br><span class="line">cashAccountCashApply.setIntro(<span class="string">""</span>);</span><br><span class="line">cashAccountCashApply.setAmount(amount);</span><br><span class="line">cashAccountCashApply.setStatus(<span class="number">1</span>);</span><br><span class="line">cashAccountCashApply.setCallbackStatus(<span class="number">0</span>);</span><br><span class="line">cashAccountCashApply.setResultStatus(<span class="number">0</span>);</span><br><span class="line">cashAccountCashApply.setType(cashAccountApplyStyle);</span><br><span class="line">cashAccountCashApply.setUserId(userId);</span><br><span class="line">cashAccountCashApply.setOrderId(<span class="string">""</span>);</span><br><span class="line"><span class="comment">//支付宝账户</span></span><br><span class="line">cashAccountCashApply.setAccount(account);</span><br><span class="line">cashAccountCashApply.setCallbackMsg(<span class="string">""</span>);</span><br><span class="line">cashAccountCashApply.setUserInfo(userInfo);</span><br><span class="line">cashAccountCashApply.setCreateTime(<span class="keyword">new</span> Date());</span><br><span class="line">cashAccountCashApply.setSuccessTime(<span class="keyword">new</span> Date());</span><br><span class="line">cashAccountCashApplyDao.save(cashAccountCashApply);</span><br></pre></td></tr></table></figure>
<ul>
<li>处理ali提现退款</li>
</ul>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">dealAliPayRefund</span><span class="params">(CashAccountCashApply cashAccountCashApply)</span> </span>&#123;</span><br><span class="line">    String prefix = env.getProperty(<span class="string">"cash.transfer.prefix"</span>);</span><br><span class="line">    String orderStr = prefix + <span class="string">"_"</span> + cashAccountCashApply.getId();</span><br><span class="line">    Float amount = cashAccountCashApply.getAmount().floatValue() / <span class="number">100</span>;</span><br><span class="line">    </span><br><span class="line">    <span class="comment">//支付宝相关信息</span></span><br><span class="line">    String app_id = <span class="string">"201xxxxxxxxxxx"</span>;</span><br><span class="line">    String privateKey = env.getProperty(<span class="string">"private_key"</span>);</span><br><span class="line">    String publicKey = env.getProperty(<span class="string">"alipay_public_key"</span>);</span><br><span class="line">    AlipayClient alipayClient = <span class="keyword">new</span> DefaultAlipayClient(<span class="string">"https://openapi.alipay.com/gateway.do"</span>, app_id, privateKey, <span class="string">"json"</span>, <span class="string">"utf-8"</span>, publicKey, <span class="string">"RSA"</span>);</span><br><span class="line">    AlipayFundTransToaccountTransferRequest request = <span class="keyword">new</span> AlipayFundTransToaccountTransferRequest();</span><br><span class="line">    request.setBizContent(<span class="string">"&#123;"</span> +</span><br><span class="line">            <span class="string">"\"out_biz_no\":\""</span> + orderStr + <span class="string">"\","</span> +</span><br><span class="line">            <span class="string">"\"payee_type\":\"ALIPAY_USERID\","</span> +</span><br><span class="line">            <span class="string">"\"payee_account\":\""</span> + cashAccountCashApply.getAccount() + <span class="string">"\","</span> +</span><br><span class="line">            <span class="string">"\"amount\":\""</span> + amount + <span class="string">"\","</span> +</span><br><span class="line">            <span class="string">"\"remark\":\"xxx提现（转账）\""</span> +</span><br><span class="line">            <span class="string">"&#125;"</span>);</span><br><span class="line">    <span class="keyword">try</span> &#123;</span><br><span class="line">        AlipayFundTransToaccountTransferResponse response = alipayClient.execute(request);</span><br><span class="line"></span><br><span class="line">        ObjectMapper objectMapper = <span class="keyword">new</span> ObjectMapper();</span><br><span class="line">        String responseString = <span class="string">"默认转账响应（问题）！"</span>;</span><br><span class="line">        <span class="keyword">try</span> &#123;</span><br><span class="line">            responseString = objectMapper.writeValueAsString(response);</span><br><span class="line">        &#125; <span class="keyword">catch</span> (JsonProcessingException je) &#123;</span><br><span class="line">            <span class="keyword">throw</span> <span class="keyword">new</span> RuntimeException(<span class="string">"ali pay refund json serialize error!"</span>);</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        <span class="keyword">if</span> (response.isSuccess()) &#123;</span><br><span class="line">            String responseOutBizNo = response.getOutBizNo();</span><br><span class="line">            <span class="keyword">if</span> (response.getCode().equals(<span class="string">"10000"</span>)) &#123;</span><br><span class="line">                <span class="comment">//成功处理逻辑</span></span><br><span class="line">                logger.info(<span class="string">"AliPayRefund-Success: outBizNo is "</span> + response.getOutBizNo());</span><br><span class="line">                Integer orderId = Integer.parseInt(responseOutBizNo.split(<span class="string">"_"</span>)[<span class="number">1</span>]);</span><br><span class="line">                <span class="keyword">if</span> (orderId.equals(cashAccountCashApply.getId())) &#123;</span><br><span class="line">                    <span class="keyword">this</span>.changeCashAccountApplyStatus(</span><br><span class="line">                            cashAccountCashApply,</span><br><span class="line">                            responseString,</span><br><span class="line">                            CashAccountApplyStatusStyle.SUCCESS_FINISH, <span class="number">1</span>, <span class="number">1</span>);</span><br><span class="line">                &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">                    <span class="keyword">this</span>.changeCashAccountApplyStatus(</span><br><span class="line">                            cashAccountCashApply,</span><br><span class="line">                            responseString,</span><br><span class="line">                            CashAccountApplyStatusStyle.WAIT_PAY_CASH, <span class="number">2</span>, <span class="number">0</span>);</span><br><span class="line">                &#125;</span><br><span class="line">            &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">                <span class="comment">//失败处理逻辑</span></span><br><span class="line">                <span class="keyword">this</span>.changeCashAccountApplyStatus(</span><br><span class="line">                        cashAccountCashApply,</span><br><span class="line">                        responseString,</span><br><span class="line">                        CashAccountApplyStatusStyle.WAIT_PAY_CASH, <span class="number">2</span>, <span class="number">0</span>);</span><br><span class="line">            &#125;</span><br><span class="line">        &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">            <span class="keyword">throw</span> <span class="keyword">new</span> RuntimeException(<span class="string">"ali pay refund error!"</span>);</span><br><span class="line">        &#125;</span><br><span class="line">    &#125; <span class="keyword">catch</span> (com.alipay.api.AlipayApiException e) &#123;</span><br><span class="line">        e.printStackTrace();</span><br><span class="line">        ObjectMapper objectMapper = <span class="keyword">new</span> ObjectMapper();</span><br><span class="line">        <span class="keyword">try</span> &#123;</span><br><span class="line">            String errorString = objectMapper.writeValueAsString(e);</span><br><span class="line">            <span class="keyword">this</span>.changeCashAccountApplyStatus(</span><br><span class="line">                    cashAccountCashApply,</span><br><span class="line">                    errorString,</span><br><span class="line">                    CashAccountApplyStatusStyle.WAIT_PAY_CASH, <span class="number">2</span>, <span class="number">0</span>);</span><br><span class="line">        &#125; <span class="keyword">catch</span> (JsonProcessingException je) &#123;</span><br><span class="line">            <span class="keyword">throw</span> <span class="keyword">new</span> RuntimeException(<span class="string">"ali pay refund json serialize error!"</span>);</span><br><span class="line">        &#125;</span><br><span class="line">        logger.info(<span class="string">"AliPayRefund-Error:"</span> + e.getErrMsg());</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
      
    </div>
    <footer class="article-footer">
      <a data-url="http://yoursite.com/2018/12/07/pay_ali 转账退款/" data-id="ckcc5iwl1002oq4uwmqr2sg4k" class="article-share-link">Teilen</a>
      
      
  <ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/ali-weixin-pay/">ali/weixin pay</a></li></ul>

    </footer>
  </div>
  
</article>


  
    <article id="post-hexo" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-meta">
    <a href="/2018/12/06/hexo/" class="article-date">
  <time datetime="2018-12-06T09:36:40.000Z" itemprop="datePublished">2018-12-06</time>
</a>
    
  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 itemprop="name">
      <a class="article-title" href="/2018/12/06/hexo/">hexo 简单搭建GitHub博客</a>
    </h1>
  

      </header>
    
    <div class="article-entry" itemprop="articleBody">
      
        <h5 id="HEXO简单使用"><a href="#HEXO简单使用" class="headerlink" title="HEXO简单使用"></a>HEXO简单使用</h5><p>hexo文档 &gt; <a href="https://hexo.io/zh-cn/docs/" target="_blank" rel="noopener">https://hexo.io/zh-cn/docs/</a></p>
<p>node下载 &gt; <a href="https://nodejs.org" target="_blank" rel="noopener">https://nodejs.org</a></p>
<h6 id="环境安装"><a href="#环境安装" class="headerlink" title="环境安装"></a>环境安装</h6><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">检查node安装:</span><br><span class="line"></span><br><span class="line">node -v</span><br><span class="line">npm -v</span><br></pre></td></tr></table></figure>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">检查git安装:</span><br><span class="line"></span><br><span class="line">git --version</span><br></pre></td></tr></table></figure>
<h6 id="注册账号-gt-https-github-com"><a href="#注册账号-gt-https-github-com" class="headerlink" title="注册账号 &gt; https://github.com/"></a>注册账号 &gt; <a href="https://github.com/" target="_blank" rel="noopener">https://github.com/</a></h6><hr>
<h6 id="全局配置设置到淘宝源："><a href="#全局配置设置到淘宝源：" class="headerlink" title="全局配置设置到淘宝源："></a>全局配置设置到淘宝源：</h6><p>git 命令窗口打开<br><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">npm config set registry https://registry.npm.taobao.org</span><br></pre></td></tr></table></figure></p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">例：</span><br><span class="line">Administrator@SC-201707251402 MINGW64 /g/vchen/blog/hexo (master)</span><br><span class="line"><span class="meta">$</span><span class="bash"> npm config <span class="built_in">set</span> registry https://registry.npm.taobao.org</span></span><br></pre></td></tr></table></figure>
<ul>
<li>设置全局配置 user.name 和 user.email</li>
</ul>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">git config –-global user.name “your name”  //(“”的账号是刚才Github里面自己注册的账号) </span><br><span class="line">git config –-global user.email “your email” //(""的邮箱是你自己注册的邮箱)</span><br></pre></td></tr></table></figure>
<ul>
<li>生成ssh密钥</li>
</ul>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line">ssh-keygen -t rsa -C “your email” //打自己的邮箱</span><br></pre></td></tr></table></figure>
<p><strong>==设置ssh key到GitHub<br>默认生成ssh key在C:\Users\username.ssh文件夹中，复制 id_rsa.pub文件到 github-&gt;settings-&gt;SSH and GPG key-&gt;new ssh key==</strong></p>
<ul>
<li>检测是否成功</li>
</ul>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ssh -T git@github.com</span><br></pre></td></tr></table></figure>
<hr>
<h6 id="hexo-安装"><a href="#hexo-安装" class="headerlink" title="hexo 安装"></a>hexo 安装</h6><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">空文件夹</span><br><span class="line"></span><br><span class="line">hexo init</span><br><span class="line">npm install</span><br><span class="line">hexo generate（可简写为hexo g） </span><br><span class="line">hexo sever（可简写为hexo s 本地测试）</span><br><span class="line">hexo deploy(可简写为hexo d 部署GitHub 需要提前配置)</span><br></pre></td></tr></table></figure>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">换端口 本地测试</span><br><span class="line">hexo s -p 5000</span><br></pre></td></tr></table></figure>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">查看版本</span><br><span class="line">hexo -V</span><br></pre></td></tr></table></figure>
<h6 id="hexo-配置文件（-config-yml）"><a href="#hexo-配置文件（-config-yml）" class="headerlink" title="hexo 配置文件（_config.yml）"></a>hexo 配置文件（_config.yml）</h6><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">deploy: </span><br><span class="line">type: git </span><br><span class="line">repo: git@github.com:yourname/yourname.github.io.git  //（改成自己的用户名和用户名加域名） </span><br><span class="line">branch: master</span><br></pre></td></tr></table></figure>
<p><strong>==冒号后要有空格==</strong></p>
<ul>
<li>部署</li>
</ul>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">hexo deploy</span><br></pre></td></tr></table></figure>
<p><strong>等待，打开类似:threadv.github.io</strong><br>更多设置可查看<a href="https://hexo.io/zh-cn/docs/" target="_blank" rel="noopener"> hexo 文档</a></p>
<hr>
<h6 id="可能出现的问题"><a href="#可能出现的问题" class="headerlink" title="可能出现的问题"></a>可能出现的问题</h6><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">$</span><span class="bash"> hexo d </span></span><br><span class="line">ERROR Deployer not found: git</span><br><span class="line">没安装之前步骤</span><br><span class="line">解决方案：</span><br><span class="line">npm install --save hexo-deployer-git</span><br></pre></td></tr></table></figure>
      
    </div>
    <footer class="article-footer">
      <a data-url="http://yoursite.com/2018/12/06/hexo/" data-id="ckcc5iwkf0022q4uwdywiqqgm" class="article-share-link">Teilen</a>
      
      
  <ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/hexo/">hexo</a></li></ul>

    </footer>
  </div>
  
</article>


  
    <article id="post-pay_即时到账交易接口" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-meta">
    <a href="/2018/11/07/pay_即时到账交易接口/" class="article-date">
  <time datetime="2018-11-07T05:20:26.000Z" itemprop="datePublished">2018-11-07</time>
</a>
    
  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 itemprop="name">
      <a class="article-title" href="/2018/11/07/pay_即时到账交易接口/">即时到账 ali</a>
    </h1>
  

      </header>
    
    <div class="article-entry" itemprop="articleBody">
      
        <h5 id="即时到账-ali"><a href="#即时到账-ali" class="headerlink" title="即时到账 ali"></a>即时到账 ali</h5><blockquote>
<p><a href="https://docs.open.alipay.com/62/103566" target="_blank" rel="noopener">https://docs.open.alipay.com/62/103566</a></p>
</blockquote>
<ul>
<li>支付获取订单和回调地址</li>
</ul>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line"><span class="meta">@RequestMapping</span>(value = <span class="string">"/getNewRechargeOrder"</span>, method = RequestMethod.POST)</span><br><span class="line">   <span class="meta">@ResponseBody</span></span><br><span class="line">   <span class="meta">@ApiOperation</span>(value = <span class="string">"即时到账交易接口-获得充值订单)"</span>, notes = <span class="string">"支付获取订单和回调地址"</span>)</span><br><span class="line">   <span class="function"><span class="keyword">public</span> BuyStorysPayApiResponse <span class="title">getNewRechargeOrder</span><span class="params">(</span></span></span><br><span class="line"><span class="function"><span class="params">           @ApiParam(value = <span class="string">"用户token"</span>)</span> @RequestParam String token,</span></span><br><span class="line"><span class="function">           @<span class="title">ApiParam</span><span class="params">(value = <span class="string">"订阅或购买订单号"</span>)</span> @RequestParam Long payOrderId,</span></span><br><span class="line"><span class="function">           @<span class="title">ApiParam</span><span class="params">(value = <span class="string">"类型"</span>)</span> @RequestParam Integer type</span></span><br><span class="line"><span class="function">   ) <span class="keyword">throws</span> ApiException </span>&#123;</span><br><span class="line">       Long userId;</span><br><span class="line">       userId = userService.checkAndGetCurrentUserId(token);</span><br><span class="line">       String appName = <span class="string">""</span>;</span><br><span class="line">       String app_id;</span><br><span class="line">       String private_key;</span><br><span class="line">       String notify_url;</span><br><span class="line">       String userAgent=request.getHeader(<span class="string">"User-Agent"</span>);</span><br><span class="line">       logger.info(<span class="string">"------------new--------getNewRechargeOrder------userAgent--"</span> + userAgent);</span><br><span class="line">       </span><br><span class="line">       app_id = env.getProperty(<span class="string">"app_id"</span>);</span><br><span class="line">       private_key = env.getProperty(<span class="string">"private_key"</span>);</span><br><span class="line">       RechargeStyle rechargeStyle=RechargeStyle.getById(type);</span><br><span class="line">       PayRechargeOrder payRechargeOrder = payService.addPayRechargeOrder(userId, payOrderId, rechargeStyle, priceId, channel, app_id, private_key, notify_url,appName);</span><br><span class="line">       BuyStorysPayApiResponse buyStorysPayApiResponse = <span class="keyword">new</span> BuyStorysPayApiResponse();</span><br><span class="line">       buyStorysPayApiResponse.setPayRechargeOrder(payRechargeOrder);</span><br><span class="line">       logger.info(<span class="string">"------------new--------getNewRechargeOrder------result--"</span> + buyStorysPayApiResponse);</span><br><span class="line">       <span class="keyword">return</span> buyStorysPayApiResponse;</span><br><span class="line">   &#125;</span><br></pre></td></tr></table></figure>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">public</span> PayRechargeOrder <span class="title">addPayRechargeOrder</span><span class="params">(Long userId, Long payOrderId, RechargeStyle type, Long priceId, String channel,String app_id,String private_key,String alipay_notify_url,String appName)</span> <span class="keyword">throws</span> ApiException </span>&#123;</span><br><span class="line"></span><br><span class="line">    Integer amount = payRechargeOrderService.getAmountByRechargeStyle(type, payOrderId.intValue(), priceId);</span><br><span class="line"></span><br><span class="line">    String prefix =env.getProperty(<span class="string">"order.prefix"</span>);</span><br><span class="line"></span><br><span class="line">    User user = userDao.findOne(userId);</span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * 生成充值订单story_pay_recharge_order</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line"></span><br><span class="line">    <span class="keyword">if</span> (channel == <span class="keyword">null</span>) &#123;</span><br><span class="line">        channel = <span class="string">""</span>;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    PayRechargeOrder payRechargeOrder = payRechargeOrderService.addPayRechargeOrder(</span><br><span class="line">            userId.intValue(),</span><br><span class="line">            amount,</span><br><span class="line">            RechargePayStyle.DEFAULT_NULL,</span><br><span class="line">            type, channel, appName</span><br><span class="line">    );</span><br><span class="line"></span><br><span class="line">    String orderStr = prefix + <span class="string">"_"</span> + payRechargeOrder.getId();</span><br><span class="line">    payRechargeOrder.setOrderCode(orderStr);</span><br><span class="line">    payRechargeOrderDao.save(payRechargeOrder);</span><br><span class="line">    payRechargeOrder.setUser(user);</span><br><span class="line">    payRechargeOrderService.setPayRechargeOrderNotifyAddress(payRechargeOrder,alipay_notify_url);</span><br><span class="line"></span><br><span class="line">    String orderString = <span class="keyword">this</span>.getAlipayStr(amount,payRechargeOrder,app_id,private_key,alipay_notify_url);</span><br><span class="line">    payRechargeOrder.setOrderString(orderString);</span><br><span class="line">    payRechargeOrderDao.save(payRechargeOrder);</span><br><span class="line">    logger.info(<span class="string">"--------------------getPayRechargeOrder----orderString-----"</span>+orderString);</span><br><span class="line">    <span class="keyword">return</span> payRechargeOrder;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * 获得alipay的支付信息。用于生成支付订单时的返回</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@return</span></span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="function"><span class="keyword">private</span> String <span class="title">getAlipayStr</span><span class="params">(<span class="keyword">int</span> amount,PayRechargeOrder payRechargeOrder,String app_id,String private_key,String notify_url)</span></span>&#123;</span><br><span class="line">        String prefix=env.getProperty(<span class="string">"order.prefix"</span>);</span><br><span class="line">        String orderStr = prefix + <span class="string">"_"</span> + payRechargeOrder.getId();</span><br><span class="line">        <span class="comment">//处理orderStr和sign</span></span><br><span class="line">        String charset=<span class="string">"utf-8"</span>;</span><br><span class="line">        String sign_type=<span class="string">"RSA"</span>;</span><br><span class="line"></span><br><span class="line">        Date now = <span class="keyword">new</span> Date();</span><br><span class="line">        SimpleDateFormat dateFormat = <span class="keyword">new</span> SimpleDateFormat(<span class="string">"yyyy-MM-dd HH:mm:ss"</span>);<span class="comment">//可以方便地修改日期格式</span></span><br><span class="line">        String timestamp = dateFormat.format( now );</span><br><span class="line"></span><br><span class="line"><span class="comment">//        String notify_url = env.getProperty("iosalipay.notify");....</span></span><br><span class="line">        String method = <span class="string">"alipay.trade.app.pay"</span>;<span class="comment">//?</span></span><br><span class="line">        String version = <span class="string">"1.0"</span>;</span><br><span class="line"><span class="comment">//        String gateway = "https://openapi.alipay.com/gateway.do";//支付宝网关</span></span><br><span class="line">        <span class="keyword">float</span> size = (<span class="keyword">float</span>)amount/<span class="number">100</span>;</span><br><span class="line">        DecimalFormat df = <span class="keyword">new</span> DecimalFormat(<span class="string">"0.00"</span>);<span class="comment">//格式化小数，不足的补0</span></span><br><span class="line">        String total_amount = df.format(size);<span class="comment">//返回的是String类型的</span></span><br><span class="line"></span><br><span class="line">        String out_trade_no = prefix+<span class="string">"_"</span>+payRechargeOrder.getId();</span><br><span class="line">        String biz_content = <span class="string">"&#123;\"timeout_express\":\"30m\",\"seller_id\":\"\",\"product_code\":\"QUICK_MSECURITY_PAY\",\"total_amount\":"</span>+total_amount+<span class="string">",\"subject\":\"支付宝支付\",\"body\":\"交易的具体描述信息\",\"out_trade_no\":"</span>+<span class="string">"\""</span>+out_trade_no+<span class="string">"\""</span>+<span class="string">"&#125;"</span>;</span><br><span class="line">        String formatStr = <span class="string">"json"</span>;</span><br><span class="line">        String originalStr;<span class="comment">//原始字符串</span></span><br><span class="line">        originalStr = <span class="string">"app_id="</span>+app_id+<span class="string">"&amp;biz_content="</span>+biz_content+<span class="string">"&amp;charset="</span>+charset+<span class="string">"&amp;format="</span>+formatStr+<span class="string">"&amp;method="</span>+method+<span class="string">"&amp;notify_url="</span>+notify_url+<span class="string">"&amp;sign_type="</span>+sign_type+<span class="string">"&amp;timestamp="</span>+timestamp+<span class="string">"&amp;version="</span>+version;</span><br><span class="line"></span><br><span class="line">        logger.info(<span class="string">"--------------------getPayRechargeOrder----biz_content-----"</span>+biz_content);</span><br><span class="line">        logger.info(<span class="string">"--------------------getPayRechargeOrder----originalStr-----"</span>+originalStr);</span><br><span class="line"></span><br><span class="line"><span class="comment">//        AlipayClient alipayClient = new DefaultAlipayClient(gateway,app_id,private_key,"json",charset,alipay_public_key,sign_type);</span></span><br><span class="line"></span><br><span class="line">        String sign = <span class="keyword">null</span>;<span class="comment">//签名</span></span><br><span class="line">        <span class="keyword">try</span> &#123;</span><br><span class="line">            sign = AlipaySignature.rsaSign(originalStr,private_key,charset,sign_type);</span><br><span class="line">            app_id = URLEncoder.encode(app_id,charset);</span><br><span class="line">            biz_content = URLEncoder.encode(biz_content,charset);</span><br><span class="line"></span><br><span class="line">            formatStr = URLEncoder.encode(formatStr,charset);</span><br><span class="line">            method = URLEncoder.encode(method,charset);</span><br><span class="line">            notify_url = URLEncoder.encode(notify_url,charset);</span><br><span class="line">            sign_type = URLEncoder.encode(sign_type,charset);</span><br><span class="line">            timestamp = URLEncoder.encode(timestamp,charset);</span><br><span class="line">            version = URLEncoder.encode(version,charset);</span><br><span class="line">            sign = URLEncoder.encode(sign,charset);</span><br><span class="line">            charset = URLEncoder.encode(charset,charset);</span><br><span class="line">        &#125; <span class="keyword">catch</span> (AlipayApiException e) &#123;</span><br><span class="line">            e.printStackTrace();</span><br><span class="line">        &#125; <span class="keyword">catch</span> (UnsupportedEncodingException e) &#123;</span><br><span class="line">            e.printStackTrace();</span><br><span class="line">        &#125;</span><br><span class="line">        String orderString = <span class="string">"app_id="</span>+app_id+<span class="string">"&amp;biz_content="</span>+biz_content+<span class="string">"&amp;charset="</span>+charset+<span class="string">"&amp;format="</span>+formatStr+<span class="string">"&amp;method="</span>+method+<span class="string">"&amp;notify_url="</span>+notify_url+<span class="string">"&amp;sign_type="</span>+sign_type+<span class="string">"&amp;timestamp="</span>+timestamp+<span class="string">"&amp;version="</span>+version+<span class="string">"&amp;sign="</span>+sign;</span><br><span class="line">        logger.info(<span class="string">"--------------------getPayRechargeOrder----orderString-----"</span>+orderString);</span><br><span class="line">        <span class="keyword">return</span> orderString;</span><br><span class="line">    &#125;</span><br></pre></td></tr></table></figure>
<hr>
<ul>
<li>回调地址<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * 新支付宝支付回调地址</span></span><br><span class="line"><span class="comment"> *</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@throws</span> Exception</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="meta">@RequestMapping</span>(value = <span class="string">"/alipayNotify"</span>, method = RequestMethod.POST)</span><br><span class="line"><span class="meta">@ResponseBody</span></span><br><span class="line"><span class="meta">@ApiOperation</span>(value = <span class="string">"新支付宝支付回调地址"</span>)</span><br><span class="line"><span class="meta">@ApiResponses</span>(&#123;<span class="meta">@ApiResponse</span>(code = <span class="number">1</span>, message = <span class="string">"成功"</span>, response = GetUserResponse.class)</span><br><span class="line">        , <span class="meta">@ApiResponse</span>(code = <span class="number">201</span>, message = <span class="string">"没有找到这个用户"</span>, response = ExceptionResponse.class)&#125;)</span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">alipayNotify</span><span class="params">(</span></span></span><br><span class="line"><span class="function"><span class="params">)</span> <span class="keyword">throws</span> Exception </span>&#123;</span><br><span class="line">    logger.info(<span class="string">"----------alipayNotify--top-appname-----"</span>);</span><br><span class="line"></span><br><span class="line">    AlipayConfig.partner = env.getProperty(<span class="string">"partner"</span>);</span><br><span class="line">    AlipayConfig.private_key = env.getProperty(<span class="string">"private_key"</span>);</span><br><span class="line">    AlipayConfig.alipay_public_key = env.getProperty(<span class="string">"alipay_public_key"</span>);</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">    logger.info(<span class="string">"------------------alipayNotify--------"</span>);</span><br><span class="line">    <span class="comment">//获取支付宝POST过来反馈信息</span></span><br><span class="line">    Map&lt;String, String&gt; params = VersionUtil.getParams(request);</span><br><span class="line"></span><br><span class="line">    logger.info(<span class="string">"-------------alipayNotify-----params---"</span> + params);</span><br><span class="line"></span><br><span class="line">    String alipaypublicKey = env.getProperty(<span class="string">"alipay_public_key"</span>);</span><br><span class="line">    String charset = <span class="string">"utf-8"</span>;</span><br><span class="line">    <span class="keyword">boolean</span> signVerfied = AlipaySignature.rsaCheckV1(params, alipaypublicKey, charset, <span class="string">"RSA"</span>);</span><br><span class="line"></span><br><span class="line">    System.out.println(<span class="string">"验证签名的结果是："</span> + signVerfied);</span><br><span class="line">    <span class="keyword">if</span> (signVerfied == <span class="keyword">false</span>) &#123;</span><br><span class="line">        response.getWriter().print(<span class="string">"fail"</span>);</span><br><span class="line">        <span class="keyword">return</span>;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment">//按照支付结果异步通知中的描述，对支付结果中的业务内容进行1\2\3\4二次校验，校验成功后在response中返回success，校验失败返回failure</span></span><br><span class="line"></span><br><span class="line">    String callbackMsg = transMapToString(params);</span><br><span class="line"></span><br><span class="line">    String prefix = env.getProperty(<span class="string">"order.prefix"</span>);</span><br><span class="line"></span><br><span class="line">    String orderIdstr = params.get(<span class="string">"out_trade_no"</span>);</span><br><span class="line"></span><br><span class="line">    <span class="keyword">long</span> orderId = Long.parseLong(orderIdstr.split(<span class="string">"_"</span>)[<span class="number">1</span>]);</span><br><span class="line"> </span><br><span class="line">    logger.info(<span class="string">"----------------alipayNotify----getOrderId----"</span> + orderId);</span><br><span class="line"></span><br><span class="line">    PayRechargeOrder payRechargeOrder = payRechargeOrderService.getPayRechargeOrder(orderId);</span><br><span class="line">    <span class="comment">// 获取 payAccount  buyer_id</span></span><br><span class="line">    String buyer_id = params.get(<span class="string">"buyer_id"</span>);</span><br><span class="line">    <span class="keyword">if</span> (buyer_id == <span class="keyword">null</span>) &#123;</span><br><span class="line">        buyer_id = <span class="string">""</span>;</span><br><span class="line">    &#125;</span><br><span class="line">    payRechargeOrder.setPayAccount(buyer_id);<span class="comment">//买家支付宝账号</span></span><br><span class="line"></span><br><span class="line">    String ostatus = params.get(<span class="string">"trade_status"</span>);</span><br><span class="line">    <span class="keyword">if</span> (ostatus.equals(<span class="string">"TRADE_FINISHED"</span>) || ostatus.equals(<span class="string">"TRADE_SUCCESS"</span>)) &#123;</span><br><span class="line">        logger.info(<span class="string">"-------------mtx-------alipayNotify-----TRADE_FINISHED--TRADE_SUCCESS-----"</span>);</span><br><span class="line"></span><br><span class="line">        <span class="keyword">try</span>&#123;</span><br><span class="line">            String tradeNo = params.get(<span class="string">"trade_no"</span>);</span><br><span class="line">            <span class="comment">//处理成功逻辑 添加回调数据，定单成功....</span></span><br><span class="line">            <span class="keyword">this</span>.setOrderSuccess(payRechargeOrder.getId().intValue()</span><br><span class="line">                    ,buyer_id</span><br><span class="line">                    ,RechargePayStyle.ALI_PAY</span><br><span class="line">                    ,callbackMsg</span><br><span class="line">                    ,tradeNo</span><br><span class="line">                    ,<span class="string">"支付宝支付充值"</span>);</span><br><span class="line">        &#125;<span class="keyword">catch</span> (ApiNotFoundException e)&#123;</span><br><span class="line">            e.printStackTrace();</span><br><span class="line">            response.getWriter().print(<span class="string">"fail"</span>);</span><br><span class="line">            <span class="keyword">return</span>;</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        response.getWriter().print(<span class="string">"success"</span>);</span><br><span class="line">        <span class="keyword">return</span>;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">return</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></li>
</ul>

      
    </div>
    <footer class="article-footer">
      <a data-url="http://yoursite.com/2018/11/07/pay_即时到账交易接口/" data-id="ckcc5iwl9002yq4uw9q1vzfnk" class="article-share-link">Teilen</a>
      
      
  <ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/ali-weixin-pay/">ali/weixin pay</a></li></ul>

    </footer>
  </div>
  
</article>


  
    <article id="post-pay_aliPay" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-meta">
    <a href="/2018/11/06/pay_aliPay/" class="article-date">
  <time datetime="2018-11-06T02:20:26.000Z" itemprop="datePublished">2018-11-06</time>
</a>
    
  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 itemprop="name">
      <a class="article-title" href="/2018/11/06/pay_aliPay/">aliPay</a>
    </h1>
  

      </header>
    
    <div class="article-entry" itemprop="articleBody">
      
        <h5 id="支付宝支付"><a href="#支付宝支付" class="headerlink" title="支付宝支付"></a>支付宝支付</h5><ul>
<li>生成订单</li>
</ul>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line"><span class="meta">@Override</span></span><br><span class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">addAliOrder</span><span class="params">(Integer orderId, Integer userId)</span> <span class="keyword">throws</span> Exception </span>&#123;</span><br><span class="line"></span><br><span class="line">    ShopOrder shopOrder = <span class="keyword">this</span>.findOrderById(orderId);</span><br><span class="line">    <span class="keyword">if</span> (shopOrder.getUserId() != userId.intValue()) &#123;</span><br><span class="line">        <span class="keyword">throw</span> <span class="keyword">new</span> RuntimeException(<span class="string">"非此用户订单"</span>);</span><br><span class="line">    &#125;</span><br><span class="line">    ShopGoods shopGoods = shopGoodsDao.findOne(shopOrder.getGoodsId());</span><br><span class="line">    Float totalAmount = (<span class="keyword">float</span>) shopOrder.getTotalAmount() / <span class="number">100</span>;</span><br><span class="line">    String totalAmountStr = totalAmount.toString();</span><br><span class="line">    <span class="keyword">this</span>.initAliWapPay(orderId, shopGoods.getGoodsName(), totalAmountStr, <span class="string">"xxx商城订单【"</span> + shopGoods.getGoodsName() + <span class="string">"】"</span>, httpResponse);</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="meta">@Override</span></span><br><span class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">initAliWapPay</span><span class="params">(Integer orderId, String subject, String totalAmount, String body, HttpServletResponse httpResponse)</span> <span class="keyword">throws</span> Exception </span>&#123;</span><br><span class="line"></span><br><span class="line">    String orderPrefix = env.getProperty(<span class="string">"shopOrder.prefix"</span>);</span><br><span class="line">    String out_trade_no = orderPrefix + <span class="string">"_"</span> + orderId;</span><br><span class="line">    String timeout_express = <span class="string">"2m"</span>;</span><br><span class="line">    String product_code = <span class="string">"QUICK_WAP_WAY"</span>;</span><br><span class="line">    AlipayClient client = userTokenService.getAlipayClient();</span><br><span class="line">    AlipayTradeWapPayRequest alipay_request = <span class="keyword">new</span> AlipayTradeWapPayRequest();</span><br><span class="line">    AlipayTradeWapPayModel model = <span class="keyword">new</span> AlipayTradeWapPayModel();</span><br><span class="line">    model.setOutTradeNo(out_trade_no);</span><br><span class="line">    model.setSubject(subject);</span><br><span class="line">    model.setTotalAmount(totalAmount);</span><br><span class="line">    model.setBody(body);</span><br><span class="line">    model.setTimeoutExpress(timeout_express);</span><br><span class="line">    model.setProductCode(product_code);</span><br><span class="line">    alipay_request.setBizModel(model);</span><br><span class="line">    <span class="comment">// 设置异步通知地址</span></span><br><span class="line">    String notifyUrl = env.getProperty(<span class="string">"shopAliPay.notify"</span>);</span><br><span class="line">    alipay_request.setNotifyUrl(notifyUrl);</span><br><span class="line">    <span class="comment">// 设置同步地址</span></span><br><span class="line">    String returnUrl = env.getProperty(<span class="string">"shopAliPay.return"</span>);</span><br><span class="line">    alipay_request.setReturnUrl(returnUrl);</span><br><span class="line">    String form = <span class="string">""</span>;</span><br><span class="line">    <span class="keyword">try</span> &#123;</span><br><span class="line">        form = client.pageExecute(alipay_request).getBody();</span><br><span class="line">        httpResponse.setContentType(<span class="string">"text/html;charset=utf-8"</span>);</span><br><span class="line">        httpResponse.getWriter().write(form);</span><br><span class="line">        httpResponse.getWriter().flush();</span><br><span class="line">        httpResponse.getWriter().close();</span><br><span class="line">    &#125; <span class="keyword">catch</span> (AlipayApiException e) &#123;</span><br><span class="line">        e.printStackTrace();</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<ul>
<li>getClient</li>
</ul>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Override</span></span><br><span class="line"><span class="function"><span class="keyword">public</span> AlipayClient <span class="title">getAlipayClient</span><span class="params">()</span> </span>&#123;</span><br><span class="line">    <span class="keyword">if</span>(alipayClient == <span class="keyword">null</span>)&#123;</span><br><span class="line">        String app_id = <span class="string">"xxxxxxxxxx"</span>;</span><br><span class="line">        String privateKey = env.getProperty(<span class="string">"private_key"</span>);</span><br><span class="line">        String publicKey = env.getProperty(<span class="string">"alipay_public_key"</span>);</span><br><span class="line">        alipayClient = <span class="keyword">new</span> DefaultAlipayClient(<span class="string">"https://openapi.alipay.com/gateway.do"</span>,app_id, privateKey,<span class="string">"json"</span>,<span class="string">"utf-8"</span>,publicKey,<span class="string">"RSA"</span>);</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">return</span> alipayClient;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<ul>
<li>回调</li>
</ul>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * 宝支付回调地址</span></span><br><span class="line"><span class="comment"> *</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@throws</span> Exception</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="meta">@RequestMapping</span>(value = <span class="string">"/aliPayNotify"</span>, method = RequestMethod.POST)</span><br><span class="line"><span class="meta">@ResponseBody</span></span><br><span class="line"><span class="meta">@ApiOperation</span>(value = <span class="string">"支付宝支付回调地址"</span>, notes = <span class="string">"支付宝支付回调地址"</span>)</span><br><span class="line"><span class="meta">@ApiResponses</span>(&#123;</span><br><span class="line">        <span class="meta">@ApiResponse</span>(code = <span class="number">1</span>, message = <span class="string">"成功"</span>, response = GetUserResponse.class),</span><br><span class="line">        <span class="meta">@ApiResponse</span>(code = <span class="number">201</span>, message = <span class="string">"没有找到这个用户"</span>, response = ExceptionResponse.class)</span><br><span class="line">&#125;)</span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">shopAliNotify</span><span class="params">()</span> <span class="keyword">throws</span> Exception </span>&#123;</span><br><span class="line">    String alipayPublicKey = env.getProperty(<span class="string">"alipay_public_key"</span>);</span><br><span class="line">    <span class="keyword">boolean</span> verifyStatus = AlipayNotify.rsaAliPayCheckV1(alipayPublicKey, request);</span><br><span class="line">    <span class="keyword">if</span> (verifyStatus) &#123;</span><br><span class="line">        String orderPrefix = env.getProperty(<span class="string">"shopOrder.prefix"</span>);</span><br><span class="line">        AlipayNotify alipayNotify = <span class="keyword">new</span> AlipayNotify(request, orderPrefix);</span><br><span class="line">        <span class="keyword">if</span> (alipayNotify.getTradeSuccess()) &#123;</span><br><span class="line">            String callBackMsg = alipayNotify.getCallbackMsg();</span><br><span class="line">            Integer orderId = alipayNotify.getOrderId().intValue();</span><br><span class="line">            <span class="comment">//...</span></span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<ul>
<li>AlipayNotify</li>
</ul>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">AlipayNotify</span> </span>&#123;</span><br><span class="line"></span><br><span class="line">    Map&lt;String, String&gt; m;</span><br><span class="line">    String callbackMsg;</span><br><span class="line">    String orderIdstr;</span><br><span class="line">    Long orderId;</span><br><span class="line">    String trade_no;</span><br><span class="line">    String sign;</span><br><span class="line">    String tradeStatus;</span><br><span class="line">    String outTradeNo;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="title">AlipayNotify</span><span class="params">(HttpServletRequest request, String orderPrefix)</span> </span>&#123;</span><br><span class="line">        Map&lt;String, String[]&gt; params = request.getParameterMap();</span><br><span class="line">        sign = request.getParameter(<span class="string">"sign"</span>);</span><br><span class="line">        m = <span class="keyword">new</span> HashMap&lt;&gt;();</span><br><span class="line"></span><br><span class="line">        <span class="keyword">if</span> (params.get(<span class="string">"body"</span>) != <span class="keyword">null</span>) &#123;</span><br><span class="line">            m.put(<span class="string">"body"</span>, params.get(<span class="string">"body"</span>)[<span class="number">0</span>]);</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">if</span> (params.get(<span class="string">"buyer_id"</span>) != <span class="keyword">null</span>) &#123;</span><br><span class="line">            m.put(<span class="string">"buyer_id"</span>, params.get(<span class="string">"buyer_id"</span>)[<span class="number">0</span>]);</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">if</span> (params.get(<span class="string">"gmt_create"</span>) != <span class="keyword">null</span>) &#123;</span><br><span class="line">            m.put(<span class="string">"gmt_create"</span>, request.getParameter(<span class="string">"gmt_create"</span>));</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">if</span> (params.get(<span class="string">"gmt_payment"</span>) != <span class="keyword">null</span>) &#123;</span><br><span class="line">            m.put(<span class="string">"gmt_payment"</span>, request.getParameter(<span class="string">"gmt_payment"</span>));</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">if</span> (params.get(<span class="string">"notify_id"</span>) != <span class="keyword">null</span>) &#123;</span><br><span class="line">            m.put(<span class="string">"notify_id"</span>, params.get(<span class="string">"notify_id"</span>)[<span class="number">0</span>]);</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">if</span> (params.get(<span class="string">"notify_time"</span>) != <span class="keyword">null</span>) &#123;</span><br><span class="line">            m.put(<span class="string">"notify_time"</span>, params.get(<span class="string">"notify_time"</span>)[<span class="number">0</span>]);</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">if</span> (params.get(<span class="string">"notify_type"</span>) != <span class="keyword">null</span>) &#123;</span><br><span class="line">            m.put(<span class="string">"notify_type"</span>, params.get(<span class="string">"notify_type"</span>)[<span class="number">0</span>]);</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">if</span> (params.get(<span class="string">"out_trade_no"</span>) != <span class="keyword">null</span>) &#123;</span><br><span class="line">            m.put(<span class="string">"out_trade_no"</span>, params.get(<span class="string">"out_trade_no"</span>)[<span class="number">0</span>]);</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">if</span> (params.get(<span class="string">"seller_email"</span>) != <span class="keyword">null</span>) &#123;</span><br><span class="line">            m.put(<span class="string">"seller_email"</span>, params.get(<span class="string">"seller_email"</span>)[<span class="number">0</span>]);</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">if</span> (params.get(<span class="string">"seller_id"</span>) != <span class="keyword">null</span>) &#123;</span><br><span class="line">            m.put(<span class="string">"seller_id"</span>, params.get(<span class="string">"seller_id"</span>)[<span class="number">0</span>]);</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">if</span> (params.get(<span class="string">"subject"</span>) != <span class="keyword">null</span>) &#123;</span><br><span class="line">            m.put(<span class="string">"subject"</span>, params.get(<span class="string">"subject"</span>)[<span class="number">0</span>]);</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">if</span> (params.get(<span class="string">"trade_status"</span>) != <span class="keyword">null</span>) &#123;</span><br><span class="line">            m.put(<span class="string">"trade_status"</span>, params.get(<span class="string">"trade_status"</span>)[<span class="number">0</span>]);</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">if</span> (params.get(<span class="string">"out_trade_no"</span>) != <span class="keyword">null</span>) &#123;</span><br><span class="line">            m.put(<span class="string">"out_trade_no"</span>, params.get(<span class="string">"out_trade_no"</span>)[<span class="number">0</span>]);</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">if</span> (params.get(<span class="string">"trade_no"</span>) != <span class="keyword">null</span>) &#123;</span><br><span class="line">            m.put(<span class="string">"trade_no"</span>, params.get(<span class="string">"trade_no"</span>)[<span class="number">0</span>]);</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">if</span> (params.get(<span class="string">"sign"</span>) != <span class="keyword">null</span>) &#123;</span><br><span class="line">            m.put(<span class="string">"sign"</span>, params.get(<span class="string">"sign"</span>)[<span class="number">0</span>]);</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        <span class="comment">//属性参数</span></span><br><span class="line">        <span class="keyword">if</span> (params.get(<span class="string">"trade_no"</span>) != <span class="keyword">null</span>) &#123;</span><br><span class="line">            <span class="keyword">this</span>.trade_no = params.get(<span class="string">"trade_no"</span>)[<span class="number">0</span>];</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">if</span> (params.get(<span class="string">"out_trade_no"</span>) != <span class="keyword">null</span>) &#123;</span><br><span class="line">            <span class="keyword">this</span>.outTradeNo = params.get(<span class="string">"out_trade_no"</span>)[<span class="number">0</span>];</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">if</span> (params.get(<span class="string">"trade_status"</span>) != <span class="keyword">null</span>) &#123;</span><br><span class="line">            <span class="keyword">this</span>.tradeStatus = params.get(<span class="string">"trade_status"</span>)[<span class="number">0</span>];</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">this</span>.callbackMsg = Map2StringUtil.mapToString(m);</span><br><span class="line">        orderIdstr = params.get(<span class="string">"out_trade_no"</span>)[<span class="number">0</span>];</span><br><span class="line">        <span class="keyword">if</span> (<span class="keyword">this</span>.orderIdstr.contains(<span class="string">"_"</span>)) &#123;</span><br><span class="line">            <span class="keyword">if</span> (!<span class="keyword">this</span>.orderIdstr.split(<span class="string">"_"</span>)[<span class="number">0</span>].equals(orderPrefix)) &#123;</span><br><span class="line">                <span class="keyword">throw</span> <span class="keyword">new</span> RuntimeException(<span class="string">"not find prefix"</span> + orderPrefix);</span><br><span class="line">            &#125;</span><br><span class="line">            orderId = Long.parseLong(<span class="keyword">this</span>.orderIdstr.split(<span class="string">"_"</span>)[<span class="number">1</span>]);</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">public</span> String <span class="title">getTradeStatus</span><span class="params">()</span> </span>&#123;</span><br><span class="line">        <span class="keyword">return</span> tradeStatus;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * 获取订单是否支付成功的状态</span></span><br><span class="line"><span class="comment">     *</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@return</span></span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">boolean</span> <span class="title">getTradeSuccess</span><span class="params">()</span> </span>&#123;</span><br><span class="line">        <span class="keyword">if</span> (<span class="keyword">this</span>.tradeStatus.equals(<span class="string">"TRADE_SUCCESS"</span>) || <span class="keyword">this</span>.tradeStatus.equals(<span class="string">"TRADE_FINISHED"</span>)) &#123;</span><br><span class="line">            <span class="keyword">return</span> <span class="keyword">true</span>;</span><br><span class="line">        &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">            <span class="keyword">return</span> <span class="keyword">false</span>;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">public</span> Map&lt;String, String&gt; <span class="title">getRequestMap</span><span class="params">()</span> </span>&#123;</span><br><span class="line">        <span class="keyword">return</span> m;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">public</span> String <span class="title">getCallbackMsg</span><span class="params">()</span> </span>&#123;</span><br><span class="line">        <span class="keyword">return</span> callbackMsg;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">public</span> String <span class="title">getOrderIdstr</span><span class="params">()</span> </span>&#123;</span><br><span class="line">        <span class="keyword">return</span> orderIdstr;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">public</span> Long <span class="title">getOrderId</span><span class="params">()</span> </span>&#123;</span><br><span class="line">        <span class="keyword">return</span> orderId;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">public</span> String <span class="title">getTrade_no</span><span class="params">()</span> </span>&#123;</span><br><span class="line">        <span class="keyword">return</span> trade_no;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">public</span> String <span class="title">getSign</span><span class="params">()</span> </span>&#123;</span><br><span class="line">        <span class="keyword">return</span> sign;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">boolean</span> <span class="title">rsaAliPayCheckV1</span><span class="params">(String alipayPublicKey, HttpServletRequest request)</span> <span class="keyword">throws</span> Exception </span>&#123;</span><br><span class="line">        <span class="comment">/**</span></span><br><span class="line"><span class="comment">         * 获取支付宝POST过来反馈信息</span></span><br><span class="line"><span class="comment">         */</span></span><br><span class="line">        Map&lt;String, String&gt; params = VersionUtil.getParams(request);</span><br><span class="line">        String charset = <span class="string">"utf-8"</span>;</span><br><span class="line">        <span class="keyword">boolean</span> verify_result = AlipaySignature.rsaCheckV1(params, alipayPublicKey, charset, <span class="string">"RSA"</span>);</span><br><span class="line">        <span class="keyword">if</span> (!verify_result) &#123;</span><br><span class="line">            <span class="keyword">return</span> <span class="keyword">false</span>;</span><br><span class="line">        &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">            <span class="keyword">return</span> <span class="keyword">true</span>;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
      
    </div>
    <footer class="article-footer">
      <a data-url="http://yoursite.com/2018/11/06/pay_aliPay/" data-id="ckcc5iwl5002sq4uw6lrnskhc" class="article-share-link">Teilen</a>
      
      
  <ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/ali-weixin-pay/">ali/weixin pay</a></li></ul>

    </footer>
  </div>
  
</article>


  
    <article id="post-pay_wxPay" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-meta">
    <a href="/2018/11/06/pay_wxPay/" class="article-date">
  <time datetime="2018-11-06T02:20:26.000Z" itemprop="datePublished">2018-11-06</time>
</a>
    
  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 itemprop="name">
      <a class="article-title" href="/2018/11/06/pay_wxPay/">wxPay</a>
    </h1>
  

      </header>
    
    <div class="article-entry" itemprop="articleBody">
      
        <h5 id="微信支付"><a href="#微信支付" class="headerlink" title="微信支付"></a>微信支付</h5><ul>
<li>生成订单</li>
</ul>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//微信下单支付</span></span><br><span class="line">String appid = MyEnv.env.getProperty(<span class="string">"appid"</span>);</span><br><span class="line">String mch_id = MyEnv.env.getProperty(<span class="string">"mch_id"</span>);</span><br><span class="line">String wxkey = env.getProperty(<span class="string">"wxkey"</span>);</span><br><span class="line"><span class="comment">//回调地址</span></span><br><span class="line">String callBackUrl = env.getProperty(<span class="string">"shopWeixinPay.notify"</span>);</span><br><span class="line">String outTradeNo = env.getProperty(<span class="string">"shopOrder.prefix"</span>) + <span class="string">"_"</span> + shopOrder.getId();</span><br><span class="line"></span><br><span class="line">String wapUrl = env.getProperty(<span class="string">"shopWechatPayWapUrl"</span>);</span><br><span class="line">String sceneInfo = <span class="string">"&#123;\"h5_info\": &#123;\"type\":\"Wap\",\"wap_url\": \""</span> + wapUrl + <span class="string">"\",\"wap_name\": \"xxxx商城\"&#125;&#125;"</span>;</span><br><span class="line"></span><br><span class="line"><span class="comment">//下单</span></span><br><span class="line">JSONObject jsonObject = weiXinOrderService.doUnifiedOrder(outTradeNo, <span class="string">"xxx商城订单"</span>, shopOrder.getTotalAmount(), shopOrder.getGoodsId().toString(), request, <span class="keyword">null</span>, wxkey, callBackUrl, <span class="string">"MWEB"</span>, sceneInfo, appid, mch_id);</span><br><span class="line">Map jsonMap = JSONObject.fromObject(jsonObject);</span><br><span class="line">String webUrl = jsonMap.get(<span class="string">"mweb_url"</span>).toString();</span><br><span class="line">String redirect = env.getProperty(<span class="string">"shopOrder.success.url"</span>) + shopOrder.getId();</span><br><span class="line">String wechatPayUrl = webUrl + <span class="string">"&amp;redirect_url="</span> + URLEncoder.encode(redirect, <span class="string">"utf-8"</span>);</span><br><span class="line">response.setWebUrl(wechatPayUrl);</span><br></pre></td></tr></table></figure>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * 扫码支付  下单返回信息</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="meta">@Override</span></span><br><span class="line"><span class="function"><span class="keyword">public</span> JSONObject <span class="title">doUnifiedOrder</span><span class="params">(String outTradeNo, String goodsName, Integer goodsPrice, String goodsId, HttpServletRequest request, String openId, String wxkey, String callBackUrl, String tradeType, String sceneInfo, String appId, String mchId)</span> </span>&#123;</span><br><span class="line"></span><br><span class="line">    String ip = HttpRequest.getIpAddr(request);</span><br><span class="line">    <span class="keyword">try</span> &#123;</span><br><span class="line">        JSONObject jsonObject = <span class="keyword">this</span>.doUnifiedOrderWx(outTradeNo, goodsName, goodsPrice, goodsId,ip,openId,wxkey, callBackUrl, tradeType, sceneInfo, appId, mchId);</span><br><span class="line">        <span class="keyword">return</span> jsonObject;</span><br><span class="line">    &#125; <span class="keyword">catch</span> (Exception e) &#123;</span><br><span class="line">        e.printStackTrace();</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">return</span> <span class="keyword">null</span>;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">  <span class="meta">@Override</span></span><br><span class="line"><span class="function"><span class="keyword">public</span> JSONObject <span class="title">doUnifiedOrderWx</span><span class="params">(String outTradeNo, String goodsName, Integer goodsPrice, String goodsId,String ip,String openId,String wxkey, String callBackUrl, String tradeType, String sceneInfo, String appId, String mchId)</span> </span>&#123;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">try</span> &#123;</span><br><span class="line">        <span class="comment">//证书文件</span></span><br><span class="line">        String certpath = env.getProperty(<span class="string">"certPath"</span>);</span><br><span class="line">        config = WXPayConfigImpl.getInstance(certpath, appId, mchId);</span><br><span class="line">        wxpay = <span class="keyword">new</span> WXPay(config);</span><br><span class="line">    &#125; <span class="keyword">catch</span> (Exception e) &#123;</span><br><span class="line">        e.printStackTrace();</span><br><span class="line">    &#125;</span><br><span class="line">    HashMap&lt;String, String&gt; data = <span class="keyword">new</span> HashMap&lt;String, String&gt;();</span><br><span class="line">    data.put(<span class="string">"body"</span>, goodsName);</span><br><span class="line">    data.put(<span class="string">"out_trade_no"</span>, outTradeNo);</span><br><span class="line">    data.put(<span class="string">"fee_type"</span>, <span class="string">"CNY"</span>);</span><br><span class="line">    data.put(<span class="string">"device_info"</span>, <span class="string">""</span>);</span><br><span class="line">    data.put(<span class="string">"total_fee"</span>, goodsPrice.toString());</span><br><span class="line">    data.put(<span class="string">"spbill_create_ip"</span>, ip);</span><br><span class="line">    data.put(<span class="string">"notify_url"</span>, callBackUrl);</span><br><span class="line">    data.put(<span class="string">"trade_type"</span>, tradeType);</span><br><span class="line">    data.put(<span class="string">"product_id"</span>, goodsId);</span><br><span class="line">    <span class="keyword">if</span>(openId != <span class="keyword">null</span>)&#123;</span><br><span class="line">        data.put(<span class="string">"openid"</span>, openId);</span><br><span class="line">    &#125;</span><br><span class="line">    data.put(<span class="string">"scene_info"</span>, sceneInfo);</span><br><span class="line"></span><br><span class="line">    <span class="keyword">try</span> &#123;</span><br><span class="line">        <span class="keyword">long</span> timeMillis = System.currentTimeMillis();</span><br><span class="line">        Long timeStamp = (timeMillis/<span class="number">1000</span>);</span><br><span class="line">        Map&lt;String, String&gt; map = wxpay.unifiedOrder(data);</span><br><span class="line">        logger.info(map);</span><br><span class="line">        String appid = map.get(<span class="string">"appid"</span>);</span><br><span class="line">        String nonce_str = map.get(<span class="string">"nonce_str"</span>);</span><br><span class="line">        String prepay_id = map.get(<span class="string">"prepay_id"</span>);</span><br><span class="line"></span><br><span class="line">        String sign= <span class="string">"appId="</span>+appid+<span class="string">"&amp;nonceStr="</span>+nonce_str+<span class="string">"&amp;package=prepay_id="</span>+prepay_id+<span class="string">"&amp;signType=MD5"</span>+<span class="string">"&amp;timeStamp="</span>+timeStamp+<span class="string">"&amp;key="</span>+ wxkey;</span><br><span class="line">        System.out.println(sign);</span><br><span class="line">        String jsSign= MD5Util.MD5Encode(sign,<span class="string">"utf-8"</span>).toUpperCase();</span><br><span class="line"></span><br><span class="line">        map.put(<span class="string">"jsSign"</span>,jsSign);</span><br><span class="line">        map.put(<span class="string">"timeStamp"</span>,timeStamp.toString());<span class="comment">//当前时间戳</span></span><br><span class="line">        System.out.println(map);</span><br><span class="line">        <span class="keyword">return</span> JSONObject.fromObject(map);</span><br><span class="line">    &#125; <span class="keyword">catch</span> (Exception e) &#123;</span><br><span class="line">        e.printStackTrace();</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">return</span> <span class="keyword">null</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<ul>
<li>h5发起微信支付</li>
</ul>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">onBridgeReady</span>(<span class="params"></span>) </span>&#123;</span><br><span class="line">									WeixinJSBridge.invoke(</span><br><span class="line">										<span class="string">'getBrandWCPayRequest'</span>, &#123;</span><br><span class="line">											<span class="string">"appId"</span>: res.body.jsonObject.appid, <span class="comment">//公众号名称，由商户传入     </span></span><br><span class="line">											<span class="string">"timeStamp"</span>: res.body.jsonObject.timeStamp, <span class="comment">// 时间戳，自1970年以来的秒数     </span></span><br><span class="line">											<span class="string">"nonceStr"</span>: res.body.jsonObject.nonce_str, <span class="comment">//随机串     </span></span><br><span class="line">											<span class="string">"package"</span>: <span class="string">"prepay_id="</span> + res.body.jsonObject.prepay_id,</span><br><span class="line">											<span class="string">"signType"</span>: <span class="string">"MD5"</span>, <span class="comment">//微信签名方式：     </span></span><br><span class="line">											<span class="string">"paySign"</span>: res.body.jsonObject.jsSign <span class="comment">//微信签名</span></span><br><span class="line">										&#125;,</span><br><span class="line">										<span class="function"><span class="keyword">function</span>(<span class="params">resp</span>) </span>&#123;</span><br><span class="line"></span><br><span class="line">											<span class="keyword">if</span>(resp.err_msg == <span class="string">"get_brand_wcpay_request:ok"</span>) &#123;</span><br><span class="line">												<span class="comment">//																alert('成功' +self.vipcode )</span></span><br><span class="line">												<span class="built_in">window</span>.location.href = <span class="string">"../success/success.html?orderid="</span> + self.orderid;</span><br><span class="line">											&#125; <span class="comment">// 使用以上方式判断前端返回,微信团队郑重提示：res.err_msg将在用户支付成功后返回    ok，但并不保证它绝对可靠。</span></span><br><span class="line">											<span class="keyword">else</span> <span class="keyword">if</span>(resp.err_msg == <span class="string">"get_brand_wcpay_request:cancel"</span>) &#123;</span><br><span class="line">												self.showSelect = <span class="literal">false</span></span><br><span class="line">												self.selectActive = <span class="literal">true</span></span><br><span class="line">											&#125; <span class="keyword">else</span> &#123;</span><br><span class="line">												<span class="comment">//								alert(resp.err_msg)</span></span><br><span class="line">											&#125;</span><br><span class="line">										&#125;</span><br><span class="line">									);</span><br><span class="line">								&#125;</span><br></pre></td></tr></table></figure>
<ul>
<li><p>回调</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@CrossOrigin</span></span><br><span class="line"><span class="meta">@RequestMapping</span>(value = <span class="string">"/WxPayNotify"</span>, method = RequestMethod.POST)</span><br><span class="line"><span class="meta">@ResponseBody</span></span><br><span class="line"><span class="meta">@ApiOperation</span>(value = <span class="string">"回调地址"</span>, notes = <span class="string">"微信支付回调地址"</span>)</span><br><span class="line"><span class="meta">@ApiResponses</span>(&#123;<span class="meta">@ApiResponse</span>(code = <span class="number">1</span>, message = <span class="string">"成功"</span>, response = GetUserResponse.class)</span><br><span class="line">        , <span class="meta">@ApiResponse</span>(code = <span class="number">201</span>, message = <span class="string">"没有找到这个用户"</span>, response = ExceptionResponse.class)&#125;)</span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">wxpayNotify</span><span class="params">(</span></span></span><br><span class="line"><span class="function"><span class="params">)</span> <span class="keyword">throws</span> IOException, ApiException </span>&#123;</span><br><span class="line">    logger.info(<span class="string">"--- start wxpaynotify ---"</span>);</span><br><span class="line">    String prefix = MyEnv.env.getProperty(<span class="string">"shopOrder.prefix"</span>);</span><br><span class="line">    WeixinNotify wxNotify = <span class="keyword">new</span> WeixinNotify(request, prefix);</span><br><span class="line">    String appid = MyEnv.env.getProperty(<span class="string">"appid"</span>);</span><br><span class="line">    String wxkey = MyEnv.env.getProperty(<span class="string">"wxkey"</span>);</span><br><span class="line">    String mch_id = MyEnv.env.getProperty(<span class="string">"mch_id"</span>);</span><br><span class="line">    <span class="keyword">boolean</span> flagSign = wxNotify.checkWeixinSign(wxNotify, appid, wxkey, mch_id);</span><br><span class="line">    logger.info(<span class="string">"flagSign"</span> + flagSign);</span><br><span class="line">    <span class="comment">//验签成功</span></span><br><span class="line">    <span class="keyword">if</span> (flagSign) &#123;</span><br><span class="line">        <span class="comment">//处理业务</span></span><br><span class="line">        <span class="comment">//...</span></span><br><span class="line">        <span class="keyword">int</span> orderId = wxNotify.getOrderId().intValue();</span><br><span class="line">       </span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
</li>
<li><p>验签</p>
</li>
</ul>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br><span class="line">150</span><br><span class="line">151</span><br><span class="line">152</span><br><span class="line">153</span><br><span class="line">154</span><br><span class="line">155</span><br><span class="line">156</span><br><span class="line">157</span><br><span class="line">158</span><br><span class="line">159</span><br><span class="line">160</span><br><span class="line">161</span><br><span class="line">162</span><br></pre></td><td class="code"><pre><span class="line">   </span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">WeixinNotify</span></span>&#123;</span><br><span class="line">    Logger logger = Logger.getLogger(WeixinNotify.class);</span><br><span class="line">    <span class="keyword">public</span> String orderIdstr;</span><br><span class="line">    Long orderId;</span><br><span class="line">    String payAccount;</span><br><span class="line">    String xmlDoc;</span><br><span class="line">    Element root;</span><br><span class="line">    String tradeNo;</span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="title">WeixinNotify</span><span class="params">(HttpServletRequest request)</span> <span class="keyword">throws</span> IOException, ApiNotFoundException </span>&#123;</span><br><span class="line">        InputStream inStream = request.getInputStream();</span><br><span class="line">        ByteArrayOutputStream outSteam = <span class="keyword">new</span> ByteArrayOutputStream();</span><br><span class="line">        <span class="keyword">byte</span>[] buffer = <span class="keyword">new</span> <span class="keyword">byte</span>[<span class="number">1024</span>];</span><br><span class="line">        <span class="keyword">int</span> len = <span class="number">0</span>;</span><br><span class="line">        <span class="keyword">while</span> ((len = inStream.read(buffer)) != -<span class="number">1</span>) &#123;</span><br><span class="line">            outSteam.write(buffer, <span class="number">0</span>, len);</span><br><span class="line">        &#125;</span><br><span class="line">        outSteam.close();</span><br><span class="line">        inStream.close();</span><br><span class="line">        <span class="keyword">this</span>.xmlDoc  = <span class="keyword">new</span> String(outSteam.toByteArray(),<span class="string">"utf-8"</span>);</span><br><span class="line">        logger.info(<span class="keyword">this</span>.xmlDoc);</span><br><span class="line"></span><br><span class="line">        StringReader read = <span class="keyword">new</span> StringReader(xmlDoc);</span><br><span class="line">        InputSource source = <span class="keyword">new</span> InputSource(read);</span><br><span class="line">        SAXBuilder sb = <span class="keyword">new</span> SAXBuilder();</span><br><span class="line">        Document doc = <span class="keyword">null</span>;</span><br><span class="line">        <span class="keyword">try</span> &#123;</span><br><span class="line">            doc = sb.build(source);</span><br><span class="line">        &#125; <span class="keyword">catch</span> (JDOMException e) &#123;</span><br><span class="line">            e.printStackTrace();</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="comment">//取的根元素</span></span><br><span class="line">        root = doc.getRootElement();</span><br><span class="line">        <span class="comment">//            System.out.println(root.getName());//输出根元素的名称（测试）</span></span><br><span class="line">        Namespace ns = root.getNamespace();</span><br><span class="line"></span><br><span class="line">        <span class="comment">//获取 orderId</span></span><br><span class="line"></span><br><span class="line">        <span class="comment">//            logger.info("--------------------wxpayNotify----prefix----"+prefix);</span></span><br><span class="line"></span><br><span class="line">        <span class="keyword">this</span>.orderIdstr= root.getChild(<span class="string">"out_trade_no"</span>,ns).getText();</span><br><span class="line">        <span class="keyword">this</span>.payAccount = root.getChild(<span class="string">"openid"</span>,ns).getText();</span><br><span class="line">        <span class="keyword">this</span>.tradeNo= root.getChild(<span class="string">"transaction_id"</span>,ns).getText();</span><br><span class="line"></span><br><span class="line">        <span class="comment">//可以从订单号中区分 是单行本 还是  app</span></span><br><span class="line">        String prefix= MyEnv.env.getProperty(<span class="string">"order.prefix"</span>);</span><br><span class="line">        <span class="keyword">if</span>(<span class="keyword">this</span>.orderIdstr.contains(<span class="string">"_"</span>)) &#123;</span><br><span class="line">            orderId = Long.parseLong(<span class="keyword">this</span>.orderIdstr.split(<span class="string">"_"</span>)[<span class="number">1</span>]);</span><br><span class="line">            <span class="keyword">if</span> (!<span class="keyword">this</span>.orderIdstr.split(<span class="string">"_"</span>)[<span class="number">0</span>].equals(prefix)) &#123;</span><br><span class="line">                <span class="keyword">throw</span> <span class="keyword">new</span> ApiNotFoundException(<span class="string">"order format error;not find orderId:"</span>+<span class="keyword">this</span>.orderIdstr);</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="title">WeixinNotify</span><span class="params">(HttpServletRequest request, String orderPrefix)</span> <span class="keyword">throws</span> IOException, ApiNotFoundException </span>&#123;</span><br><span class="line">        InputStream inStream = request.getInputStream();</span><br><span class="line">        ByteArrayOutputStream outSteam = <span class="keyword">new</span> ByteArrayOutputStream();</span><br><span class="line">        <span class="keyword">byte</span>[] buffer = <span class="keyword">new</span> <span class="keyword">byte</span>[<span class="number">1024</span>];</span><br><span class="line">        <span class="keyword">int</span> len = <span class="number">0</span>;</span><br><span class="line">        <span class="keyword">while</span> ((len = inStream.read(buffer)) != -<span class="number">1</span>) &#123;</span><br><span class="line">            outSteam.write(buffer, <span class="number">0</span>, len);</span><br><span class="line">        &#125;</span><br><span class="line">        outSteam.close();</span><br><span class="line">        inStream.close();</span><br><span class="line">        <span class="keyword">this</span>.xmlDoc  = <span class="keyword">new</span> String(outSteam.toByteArray(),<span class="string">"utf-8"</span>);</span><br><span class="line">        logger.info(<span class="keyword">this</span>.xmlDoc);</span><br><span class="line"></span><br><span class="line">        StringReader read = <span class="keyword">new</span> StringReader(xmlDoc);</span><br><span class="line">        InputSource source = <span class="keyword">new</span> InputSource(read);</span><br><span class="line">        SAXBuilder sb = <span class="keyword">new</span> SAXBuilder();</span><br><span class="line">        Document doc = <span class="keyword">null</span>;</span><br><span class="line">        <span class="keyword">try</span> &#123;</span><br><span class="line">            doc = sb.build(source);</span><br><span class="line">        &#125; <span class="keyword">catch</span> (JDOMException e) &#123;</span><br><span class="line">            e.printStackTrace();</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="comment">//取的根元素</span></span><br><span class="line">        root = doc.getRootElement();</span><br><span class="line">        <span class="comment">//            System.out.println(root.getName());//输出根元素的名称（测试）</span></span><br><span class="line">        Namespace ns = root.getNamespace();</span><br><span class="line"></span><br><span class="line">        <span class="comment">//获取 orderId</span></span><br><span class="line"></span><br><span class="line">        <span class="comment">//            logger.info("--------------------wxpayNotify----prefix----"+prefix);</span></span><br><span class="line"></span><br><span class="line">        <span class="keyword">this</span>.orderIdstr= root.getChild(<span class="string">"out_trade_no"</span>,ns).getText();</span><br><span class="line">        <span class="keyword">this</span>.payAccount = root.getChild(<span class="string">"openid"</span>,ns).getText();</span><br><span class="line">        <span class="keyword">this</span>.tradeNo= root.getChild(<span class="string">"transaction_id"</span>,ns).getText();</span><br><span class="line"></span><br><span class="line">        <span class="comment">//可以从订单号中区分 是单行本 还是  app</span></span><br><span class="line">        <span class="keyword">if</span>(<span class="keyword">this</span>.orderIdstr.contains(<span class="string">"_"</span>)) &#123;</span><br><span class="line">            orderId = Long.parseLong(<span class="keyword">this</span>.orderIdstr.split(<span class="string">"_"</span>)[<span class="number">1</span>]);</span><br><span class="line">            <span class="keyword">if</span> (!<span class="keyword">this</span>.orderIdstr.split(<span class="string">"_"</span>)[<span class="number">0</span>].equals(orderPrefix)) &#123;</span><br><span class="line">                <span class="keyword">throw</span> <span class="keyword">new</span> ApiNotFoundException(<span class="string">"order format error;not find orderId:"</span>+<span class="keyword">this</span>.orderIdstr);</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">public</span> String <span class="title">getOrderIdstr</span><span class="params">()</span> </span>&#123;</span><br><span class="line">        <span class="keyword">return</span> orderIdstr;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">public</span> String <span class="title">getPayAccount</span><span class="params">()</span> </span>&#123;</span><br><span class="line">        <span class="keyword">return</span> payAccount;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">public</span> String <span class="title">getXmlDoc</span><span class="params">()</span> </span>&#123;</span><br><span class="line">        <span class="keyword">return</span> xmlDoc;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">public</span> Element <span class="title">getRoot</span><span class="params">()</span> </span>&#123;</span><br><span class="line">        <span class="keyword">return</span> root;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">public</span> String <span class="title">getTradeNo</span><span class="params">()</span> </span>&#123;</span><br><span class="line">        <span class="keyword">if</span>(tradeNo==<span class="keyword">null</span>)&#123;</span><br><span class="line">            <span class="keyword">return</span> <span class="string">""</span>;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">return</span> tradeNo;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">public</span> Long <span class="title">getOrderId</span><span class="params">()</span> </span>&#123;</span><br><span class="line">        <span class="keyword">return</span> orderId;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * 微信验签</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@return</span> true成功 false失败</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">boolean</span> <span class="title">checkWeixinSign</span><span class="params">(WeixinNotify weixinNotify,String appid,String wxkey,String mch_id)</span></span>&#123;</span><br><span class="line"></span><br><span class="line">        <span class="comment">//参数：开始生成签名</span></span><br><span class="line">        SortedMap&lt;Object,Object&gt; parameters = <span class="keyword">new</span> TreeMap&lt;Object,Object&gt;();</span><br><span class="line">        List&lt;Element&gt; alle=weixinNotify.getRoot().getChildren();</span><br><span class="line"></span><br><span class="line">        Namespace namespace = weixinNotify.getRoot().getNamespace();</span><br><span class="line"></span><br><span class="line">        System.out.println(alle.get(<span class="number">1</span>));</span><br><span class="line">        <span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">0</span>;i&lt;alle.size();i++)&#123;</span><br><span class="line">            <span class="comment">//Element sstr=alle.get(i);</span></span><br><span class="line">            String key=alle.get(i).getName();</span><br><span class="line">            <span class="keyword">if</span>(key.equals(<span class="string">"sign"</span>) || key.equals(<span class="string">"appid"</span>)  || key.equals(<span class="string">"mch_id"</span>) )&#123;</span><br><span class="line">                <span class="keyword">continue</span>;</span><br><span class="line">            &#125;</span><br><span class="line">            <span class="comment">//System.out.println(sstr.getName());</span></span><br><span class="line">            parameters.put(key, weixinNotify.getRoot().getChild(key,namespace).getText());</span><br><span class="line">        &#125;</span><br><span class="line">        parameters.put(<span class="string">"appid"</span>, appid);</span><br><span class="line">        parameters.put(<span class="string">"mch_id"</span>, mch_id);</span><br><span class="line">        <span class="comment">//生成签名</span></span><br><span class="line">        String sign = WXSignUtils.createSign(<span class="string">"UTF-8"</span>, parameters,wxkey);</span><br><span class="line">        logger.info(<span class="string">"签名是："</span>+sign);</span><br><span class="line">        logger.info(<span class="string">"返回签名是："</span>+weixinNotify.getRoot().getChild(<span class="string">"sign"</span>,namespace).getText());</span><br><span class="line">        <span class="keyword">if</span>(!sign.equals(weixinNotify.getRoot().getChild(<span class="string">"sign"</span>,namespace).getText()))&#123;<span class="comment">//验签失败</span></span><br><span class="line">        <span class="comment">//            logger.info("fail");</span></span><br><span class="line"></span><br><span class="line">            <span class="keyword">return</span> <span class="keyword">false</span>;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">return</span> <span class="keyword">true</span>;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<ul>
<li>生成签名</li>
</ul>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line">   <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> String <span class="title">createSign</span><span class="params">(String characterEncoding,SortedMap&lt;Object,Object&gt; parameters,String key)</span></span>&#123;</span><br><span class="line">	StringBuffer sb = <span class="keyword">new</span> StringBuffer();</span><br><span class="line">	Set es = parameters.entrySet();<span class="comment">//</span></span><br><span class="line">	Iterator it = es.iterator();</span><br><span class="line">	<span class="keyword">while</span>(it.hasNext()) &#123;</span><br><span class="line">		Map.Entry entry = (Map.Entry)it.next();</span><br><span class="line">		String k = (String)entry.getKey();</span><br><span class="line">		Object v = entry.getValue();</span><br><span class="line">		<span class="keyword">if</span>(<span class="keyword">null</span> != v &amp;&amp; !<span class="string">""</span>.equals(v) </span><br><span class="line">				&amp;&amp; !<span class="string">"sign"</span>.equals(k) &amp;&amp; !<span class="string">"key"</span>.equals(k)) &#123;</span><br><span class="line">			sb.append(k + <span class="string">"="</span> + v + <span class="string">"&amp;"</span>);</span><br><span class="line">		&#125;</span><br><span class="line">	&#125;</span><br><span class="line">	sb.append(<span class="string">"key="</span> + key);</span><br><span class="line">	System.out.println(<span class="string">"字符串拼接后是"</span>+sb.toString());</span><br><span class="line">	String sign = MD5Util.MD5Encode(sb.toString(), characterEncoding).toUpperCase();</span><br><span class="line">	<span class="keyword">return</span> sign;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
      
    </div>
    <footer class="article-footer">
      <a data-url="http://yoursite.com/2018/11/06/pay_wxPay/" data-id="ckcc5iwl8002wq4uwcklwxlov" class="article-share-link">Teilen</a>
      
      
  <ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/ali-weixin-pay/">ali/weixin pay</a></li></ul>

    </footer>
  </div>
  
</article>


  
    <article id="post-多线程查询" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-meta">
    <a href="/2018/11/05/多线程查询/" class="article-date">
  <time datetime="2018-11-05T03:20:36.000Z" itemprop="datePublished">2018-11-05</time>
</a>
    
  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 itemprop="name">
      <a class="article-title" href="/2018/11/05/多线程查询/">多线程查询</a>
    </h1>
  

      </header>
    
    <div class="article-entry" itemprop="articleBody">
      
        <h5 id="线程简单使用"><a href="#线程简单使用" class="headerlink" title="线程简单使用"></a>线程简单使用</h5><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">ThreadResult</span></span>&#123;</span><br><span class="line">      <span class="keyword">public</span> List&lt;GroupStoryThread&gt; storyThreads=<span class="keyword">new</span> ArrayList&lt;&gt;();</span><br><span class="line">      <span class="keyword">public</span> List&lt;GroupSerialThread&gt; serialThreads=<span class="keyword">new</span> ArrayList&lt;&gt;();</span><br><span class="line">      <span class="keyword">public</span> GroupAdThread groupAdThread=<span class="keyword">null</span>;</span><br><span class="line">      <span class="keyword">public</span> GroupPromptThread groupPromptThread=<span class="keyword">null</span>;</span><br><span class="line">  &#125;</span><br></pre></td></tr></table></figure>
<h6 id="线程"><a href="#线程" class="headerlink" title="线程"></a>线程</h6><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line">public class GroupStoryThread implements Runnable &#123;</span><br><span class="line">    Logger logger=Logger.getLogger(GroupSerialThread.class);</span><br><span class="line">    GroupRelevanceService groupRelevanceService;</span><br><span class="line">    Page&lt;Story&gt; storyPage;</span><br><span class="line">    User user;</span><br><span class="line">    int groupId;</span><br><span class="line">    int pageNo;</span><br><span class="line">    int pageSize;</span><br><span class="line">    public GroupStoryThread(GroupRelevanceService groupRelevanceService, User user, int groupId, int pageNo, int pageSize)&#123;</span><br><span class="line">        this.groupRelevanceService=groupRelevanceService;</span><br><span class="line">        this.user=user;</span><br><span class="line">        this.groupId=groupId;</span><br><span class="line">        this.pageNo=pageNo;</span><br><span class="line">        this.pageSize=pageSize;</span><br><span class="line">    &#125;</span><br><span class="line">    @Override</span><br><span class="line">    public void run() &#123;</span><br><span class="line">//        logger.info(&quot;------storys begin&quot;);</span><br><span class="line">       storyPage = groupRelevanceService.getNewGroupStoryList(user, groupId, pageNo, pageSize);</span><br><span class="line">//        logger.info(&quot;------storys end&quot;);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    public Page&lt;Story&gt; getStoryPage() &#123;</span><br><span class="line">        return storyPage;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    public int getGroupId() &#123;</span><br><span class="line">        return groupId;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">GroupSerialThread</span> <span class="keyword">implements</span> <span class="title">Runnable</span> </span>&#123;</span><br><span class="line">    Logger logger=Logger.getLogger(GroupSerialThread.class);</span><br><span class="line"></span><br><span class="line">    SerialStoryStyle serialStoryStyle;</span><br><span class="line"></span><br><span class="line">    SerialStoryService serialStoryService;</span><br><span class="line">    List&lt;SerialStory&gt; serialStoryList;</span><br><span class="line">    User user;</span><br><span class="line">    Integer pageNo;</span><br><span class="line">    Integer pageSize;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="title">GroupSerialThread</span><span class="params">(SerialStoryService serialStoryService,SerialStoryStyle serialStoryStyle, User user, <span class="keyword">int</span> pageNo, <span class="keyword">int</span> pageSize)</span></span>&#123;</span><br><span class="line">        <span class="keyword">this</span>.serialStoryService=serialStoryService;</span><br><span class="line">        <span class="keyword">this</span>.user=user;</span><br><span class="line">        <span class="keyword">this</span>.pageNo=pageNo;</span><br><span class="line">        <span class="keyword">this</span>.pageSize=pageSize;</span><br><span class="line">        <span class="keyword">this</span>.serialStoryStyle=serialStoryStyle;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="meta">@Override</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">run</span><span class="params">()</span> </span>&#123;</span><br><span class="line"><span class="comment">//        logger.info("-----begin serial");</span></span><br><span class="line">        <span class="keyword">int</span> userid=<span class="number">0</span>;</span><br><span class="line">        <span class="keyword">if</span>(user!=<span class="keyword">null</span>)&#123;</span><br><span class="line">            userid=user.getId().intValue();</span><br><span class="line">        &#125;</span><br><span class="line">        Page&lt;SerialStory&gt; serialStoryPage = serialStoryService.getCommonSerialStoryPage((<span class="keyword">long</span>)userid, serialStoryStyle, pageNo,pageSize);</span><br><span class="line">        serialStoryList = serialStoryPage.getContent();</span><br><span class="line">        <span class="keyword">for</span>(SerialStory item : serialStoryList)&#123;</span><br><span class="line">            serialStoryService.setSerialStoryIsBuy(user,item);</span><br><span class="line">        &#125;</span><br><span class="line"><span class="comment">//        logger.info("-----end serial");</span></span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">public</span> List&lt;SerialStory&gt; <span class="title">getSerialStoryList</span><span class="params">()</span> </span>&#123;</span><br><span class="line">        <span class="keyword">return</span> serialStoryList;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">public</span> SerialStoryStyle <span class="title">getSerialStoryStyle</span><span class="params">()</span> </span>&#123;</span><br><span class="line">        <span class="keyword">return</span> serialStoryStyle;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">GroupPromptThread</span> <span class="keyword">implements</span> <span class="title">Runnable</span> </span>&#123;</span><br><span class="line">    Logger logger=Logger.getLogger(GroupPromptThread.class);</span><br><span class="line">    PromptService promptService;</span><br><span class="line">    Prompt prompt;</span><br><span class="line">    User user;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="title">GroupPromptThread</span><span class="params">(PromptService promptService, User user)</span></span>&#123;</span><br><span class="line"></span><br><span class="line">        <span class="keyword">this</span>.promptService=promptService;</span><br><span class="line">        <span class="keyword">this</span>.user=user;</span><br><span class="line"></span><br><span class="line">    &#125;</span><br><span class="line">    <span class="meta">@Override</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">run</span><span class="params">()</span> </span>&#123;</span><br><span class="line"><span class="comment">//        logger.info("----begin prompt");</span></span><br><span class="line">        <span class="keyword">int</span> userId=<span class="number">0</span>;</span><br><span class="line">        <span class="keyword">if</span>(user!=<span class="keyword">null</span>)&#123;</span><br><span class="line">            userId=user.getId().intValue();</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">if</span>(userId!=<span class="number">0</span>)&#123;</span><br><span class="line">            <span class="keyword">try</span> &#123;</span><br><span class="line">                prompt = promptService.getPrompt(userId);</span><br><span class="line"></span><br><span class="line">            &#125;<span class="keyword">catch</span> (Exception e)&#123;</span><br><span class="line">                e.printStackTrace();</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;<span class="keyword">else</span>&#123;</span><br><span class="line">              prompt=<span class="keyword">new</span> Prompt(PromptStyle.STUDY_PLAN.getId(),PromptStyle.STUDY_PLAN.getName(),PromptStyle.STUDY_PLAN.getUrl());</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">//        logger.info("----end prompt");</span></span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">public</span> Prompt <span class="title">getPrompt</span><span class="params">()</span> </span>&#123;</span><br><span class="line">        <span class="keyword">return</span> prompt;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">GroupAdThread</span> <span class="keyword">implements</span> <span class="title">Runnable</span> </span>&#123;</span><br><span class="line">    Logger logger=Logger.getLogger(GroupAdThread.class);</span><br><span class="line">    AdService adService;</span><br><span class="line">    List&lt;Ads&gt; adsList;</span><br><span class="line">    String channel;</span><br><span class="line">    String platform;</span><br><span class="line">    User user;</span><br><span class="line">    <span class="keyword">int</span> isCheckVer;</span><br><span class="line">    String ver;</span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="title">GroupAdThread</span><span class="params">(AdService adService, String channel,String platform,<span class="keyword">int</span> isCheckVer,String ver,User user)</span></span>&#123;</span><br><span class="line">        <span class="keyword">this</span>.channel=channel;</span><br><span class="line">        <span class="keyword">this</span>.platform=platform;</span><br><span class="line">        <span class="keyword">this</span>.adService=adService;</span><br><span class="line">        <span class="keyword">this</span>.isCheckVer=isCheckVer;</span><br><span class="line">        <span class="keyword">this</span>.user=user;</span><br><span class="line">        <span class="keyword">this</span>.ver=ver;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">    &#125;</span><br><span class="line">    <span class="meta">@Override</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">run</span><span class="params">()</span> </span>&#123;</span><br><span class="line"><span class="comment">//        logger.info("------begin ad");</span></span><br><span class="line">        adsList=adService.getAds(<span class="number">0</span>,<span class="number">8</span>,isCheckVer,channel,platform,ver,user);</span><br><span class="line"></span><br><span class="line">        <span class="keyword">if</span>(user != <span class="keyword">null</span> &amp;&amp; user.getIsTest().equals(<span class="number">1</span>))&#123;</span><br><span class="line">            List&lt;Ads&gt; adsTestList = adService.getTestAds();</span><br><span class="line">            List&lt;Ads&gt; newAdsList = <span class="keyword">new</span> ArrayList&lt;&gt;(adsList);</span><br><span class="line">            newAdsList.addAll(adsTestList);</span><br><span class="line">            adsList=newAdsList;</span><br><span class="line">        &#125;</span><br><span class="line"><span class="comment">//        logger.info("------end ad");</span></span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">public</span> List&lt;Ads&gt; <span class="title">getAdsList</span><span class="params">()</span> </span>&#123;</span><br><span class="line">        <span class="keyword">return</span> adsList;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<hr>
<ul>
<li><p>response</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br><span class="line">150</span><br><span class="line">151</span><br><span class="line">152</span><br><span class="line">153</span><br><span class="line">154</span><br><span class="line">155</span><br><span class="line">156</span><br><span class="line">157</span><br><span class="line">158</span><br><span class="line">159</span><br><span class="line">160</span><br><span class="line">161</span><br><span class="line">162</span><br><span class="line">163</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">GetIndex280Response</span> <span class="keyword">extends</span> <span class="title">ApiResponse</span> </span>&#123;</span><br><span class="line"></span><br><span class="line">    List&lt;Ads&gt; ads;</span><br><span class="line">    <span class="comment">/** 精品推荐*/</span></span><br><span class="line">    CustomGroup recommendGroup;</span><br><span class="line">    <span class="comment">/** 最新故事*/</span></span><br><span class="line">    List&lt;DisplayGroup&gt; newStoryGroup;</span><br><span class="line">    <span class="comment">/** 精品课程 */</span></span><br><span class="line">    LessonIndex lessonIndex;</span><br><span class="line">    <span class="comment">/** 故事足迹*/</span></span><br><span class="line">    CustomGroup userReadRecordGroup;</span><br><span class="line">    <span class="comment">/**飞船电台 */</span></span><br><span class="line">    CustomGroup radioGroup;</span><br><span class="line">    <span class="comment">/**IP专区 */</span></span><br><span class="line">    CustomGroup ipStoryGroup;</span><br><span class="line">    <span class="comment">/**经典故事 &amp;&amp; 创意思维 */</span></span><br><span class="line">    List&lt;DisplayGroup&gt; classicAndCreateGroup;</span><br><span class="line">    <span class="comment">/**绘本丛书 */</span></span><br><span class="line">    CustomGroup serialGroup;</span><br><span class="line">    <span class="comment">/**情感教育 &amp;&amp;幽默故事 */</span></span><br><span class="line">    List&lt;DisplayGroup&gt; emotionAndHumourGroup;</span><br><span class="line">    <span class="comment">/**益智训练专区 */</span></span><br><span class="line">    CustomGroup gameSerialGroup;</span><br><span class="line">    <span class="comment">/**传统文化 */</span></span><br><span class="line">    List&lt;DisplayGroup&gt; traditionCultureGroup;</span><br><span class="line">    <span class="comment">/**其他分类 */</span></span><br><span class="line">    List&lt;DisplayGroup&gt; otherGroup;</span><br><span class="line"></span><br><span class="line">    Integer isSvip;</span><br><span class="line"></span><br><span class="line">    Prompt prompt;</span><br><span class="line"></span><br><span class="line">    Integer serialStoryCount;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">public</span> List&lt;Ads&gt; <span class="title">getAds</span><span class="params">()</span> </span>&#123;</span><br><span class="line">        <span class="keyword">return</span> ads;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">setAds</span><span class="params">(List&lt;Ads&gt; ads)</span> </span>&#123;</span><br><span class="line">        <span class="keyword">this</span>.ads = ads;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">public</span> CustomGroup <span class="title">getRecommendGroup</span><span class="params">()</span> </span>&#123;</span><br><span class="line">        <span class="keyword">return</span> recommendGroup;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">setRecommendGroup</span><span class="params">(CustomGroup recommendGroup)</span> </span>&#123;</span><br><span class="line">        <span class="keyword">this</span>.recommendGroup = recommendGroup;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">public</span> List&lt;DisplayGroup&gt; <span class="title">getNewStoryGroup</span><span class="params">()</span> </span>&#123;</span><br><span class="line">        <span class="keyword">return</span> newStoryGroup;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">setNewStoryGroup</span><span class="params">(List&lt;DisplayGroup&gt; newStoryGroup)</span> </span>&#123;</span><br><span class="line">        <span class="keyword">this</span>.newStoryGroup = newStoryGroup;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">public</span> LessonIndex <span class="title">getLessonIndex</span><span class="params">()</span> </span>&#123;</span><br><span class="line">        <span class="keyword">return</span> lessonIndex;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">setLessonIndex</span><span class="params">(LessonIndex lessonIndex)</span> </span>&#123;</span><br><span class="line">        <span class="keyword">this</span>.lessonIndex = lessonIndex;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">public</span> CustomGroup <span class="title">getUserReadRecordGroup</span><span class="params">()</span> </span>&#123;</span><br><span class="line">        <span class="keyword">return</span> userReadRecordGroup;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">setUserReadRecordGroup</span><span class="params">(CustomGroup userReadRecordGroup)</span> </span>&#123;</span><br><span class="line">        <span class="keyword">this</span>.userReadRecordGroup = userReadRecordGroup;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">public</span> CustomGroup <span class="title">getRadioGroup</span><span class="params">()</span> </span>&#123;</span><br><span class="line">        <span class="keyword">return</span> radioGroup;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">setRadioGroup</span><span class="params">(CustomGroup radioGroup)</span> </span>&#123;</span><br><span class="line">        <span class="keyword">this</span>.radioGroup = radioGroup;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">public</span> CustomGroup <span class="title">getIpStoryGroup</span><span class="params">()</span> </span>&#123;</span><br><span class="line">        <span class="keyword">return</span> ipStoryGroup;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">setIpStoryGroup</span><span class="params">(CustomGroup ipStoryGroup)</span> </span>&#123;</span><br><span class="line">        <span class="keyword">this</span>.ipStoryGroup = ipStoryGroup;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">public</span> List&lt;DisplayGroup&gt; <span class="title">getClassicAndCreateGroup</span><span class="params">()</span> </span>&#123;</span><br><span class="line">        <span class="keyword">return</span> classicAndCreateGroup;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">setClassicAndCreateGroup</span><span class="params">(List&lt;DisplayGroup&gt; classicAndCreateGroup)</span> </span>&#123;</span><br><span class="line">        <span class="keyword">this</span>.classicAndCreateGroup = classicAndCreateGroup;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">public</span> List&lt;DisplayGroup&gt; <span class="title">getEmotionAndHumourGroup</span><span class="params">()</span> </span>&#123;</span><br><span class="line">        <span class="keyword">return</span> emotionAndHumourGroup;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">setEmotionAndHumourGroup</span><span class="params">(List&lt;DisplayGroup&gt; emotionAndHumourGroup)</span> </span>&#123;</span><br><span class="line">        <span class="keyword">this</span>.emotionAndHumourGroup = emotionAndHumourGroup;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">public</span> CustomGroup <span class="title">getSerialGroup</span><span class="params">()</span> </span>&#123;</span><br><span class="line">        <span class="keyword">return</span> serialGroup;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">setSerialGroup</span><span class="params">(CustomGroup serialGroup)</span> </span>&#123;</span><br><span class="line">        <span class="keyword">this</span>.serialGroup = serialGroup;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">public</span> CustomGroup <span class="title">getGameSerialGroup</span><span class="params">()</span> </span>&#123;</span><br><span class="line">        <span class="keyword">return</span> gameSerialGroup;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">setGameSerialGroup</span><span class="params">(CustomGroup gameSerialGroup)</span> </span>&#123;</span><br><span class="line">        <span class="keyword">this</span>.gameSerialGroup = gameSerialGroup;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">public</span> List&lt;DisplayGroup&gt; <span class="title">getOtherGroup</span><span class="params">()</span> </span>&#123;</span><br><span class="line">        <span class="keyword">return</span> otherGroup;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">setOtherGroup</span><span class="params">(List&lt;DisplayGroup&gt; otherGroup)</span> </span>&#123;</span><br><span class="line">        <span class="keyword">this</span>.otherGroup = otherGroup;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">public</span> Integer <span class="title">getIsSvip</span><span class="params">()</span> </span>&#123;</span><br><span class="line">        <span class="keyword">return</span> isSvip;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">setIsSvip</span><span class="params">(Integer isSvip)</span> </span>&#123;</span><br><span class="line">        <span class="keyword">this</span>.isSvip = isSvip;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">public</span> Prompt <span class="title">getPrompt</span><span class="params">()</span> </span>&#123;</span><br><span class="line">        <span class="keyword">return</span> prompt;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">setPrompt</span><span class="params">(Prompt prompt)</span> </span>&#123;</span><br><span class="line">        <span class="keyword">this</span>.prompt = prompt;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">public</span> Integer <span class="title">getSerialStoryCount</span><span class="params">()</span> </span>&#123;</span><br><span class="line">        <span class="keyword">return</span> serialStoryCount;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">setSerialStoryCount</span><span class="params">(Integer serialStoryCount)</span> </span>&#123;</span><br><span class="line">        <span class="keyword">this</span>.serialStoryCount = serialStoryCount;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">public</span> List&lt;DisplayGroup&gt; <span class="title">getTraditionCultureGroup</span><span class="params">()</span> </span>&#123;</span><br><span class="line">        <span class="keyword">return</span> traditionCultureGroup;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">setTraditionCultureGroup</span><span class="params">(List&lt;DisplayGroup&gt; traditionCultureGroup)</span> </span>&#123;</span><br><span class="line">        <span class="keyword">this</span>.traditionCultureGroup = traditionCultureGroup;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
</li>
<li><p>controller </p>
</li>
</ul>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br><span class="line">150</span><br><span class="line">151</span><br><span class="line">152</span><br><span class="line">153</span><br><span class="line">154</span><br><span class="line">155</span><br><span class="line">156</span><br><span class="line">157</span><br><span class="line">158</span><br><span class="line">159</span><br><span class="line">160</span><br><span class="line">161</span><br><span class="line">162</span><br><span class="line">163</span><br><span class="line">164</span><br><span class="line">165</span><br><span class="line">166</span><br><span class="line">167</span><br><span class="line">168</span><br><span class="line">169</span><br><span class="line">170</span><br><span class="line">171</span><br><span class="line">172</span><br><span class="line">173</span><br><span class="line">174</span><br><span class="line">175</span><br><span class="line">176</span><br><span class="line">177</span><br><span class="line">178</span><br><span class="line">179</span><br><span class="line">180</span><br><span class="line">181</span><br><span class="line">182</span><br><span class="line">183</span><br><span class="line">184</span><br><span class="line">185</span><br><span class="line">186</span><br><span class="line">187</span><br><span class="line">188</span><br><span class="line">189</span><br><span class="line">190</span><br><span class="line">191</span><br><span class="line">192</span><br><span class="line">193</span><br><span class="line">194</span><br><span class="line">195</span><br><span class="line">196</span><br><span class="line">197</span><br><span class="line">198</span><br><span class="line">199</span><br><span class="line">200</span><br><span class="line">201</span><br><span class="line">202</span><br><span class="line">203</span><br><span class="line">204</span><br><span class="line">205</span><br><span class="line">206</span><br><span class="line">207</span><br><span class="line">208</span><br><span class="line">209</span><br><span class="line">210</span><br><span class="line">211</span><br><span class="line">212</span><br><span class="line">213</span><br><span class="line">214</span><br><span class="line">215</span><br><span class="line">216</span><br><span class="line">217</span><br><span class="line">218</span><br><span class="line">219</span><br><span class="line">220</span><br></pre></td><td class="code"><pre><span class="line"> <span class="meta">@RequestMapping</span>(value = <span class="string">"getIndex"</span>, method = RequestMethod.GET)</span><br><span class="line">    <span class="meta">@ResponseBody</span></span><br><span class="line">    <span class="meta">@ApiOperation</span>(value = <span class="string">"首页 版本开始"</span>)</span><br><span class="line">    <span class="function">GetIndex280Response <span class="title">getIndex</span><span class="params">(</span></span></span><br><span class="line"><span class="function"><span class="params">            @RequestHeader(value = <span class="string">"ssToken"</span>, required = <span class="keyword">false</span>)</span> String ssToken,</span></span><br><span class="line"><span class="function">            @<span class="title">ApiParam</span><span class="params">(value = <span class="string">"版本号"</span>, defaultValue = <span class="string">""</span>, required = <span class="keyword">false</span>)</span> @<span class="title">RequestParam</span><span class="params">(required = <span class="keyword">false</span>, defaultValue = <span class="string">""</span>)</span> String ver</span></span><br><span class="line"><span class="function">    ) </span>&#123;</span><br><span class="line">        GetIndex280Response response = <span class="keyword">new</span> GetIndex280Response();</span><br><span class="line">        Long loginId = (Long) request.getAttribute(<span class="string">"loginId"</span>);</span><br><span class="line">        User user = userService.getUser(loginId.intValue());</span><br><span class="line">        <span class="keyword">int</span> userid=<span class="number">0</span>;</span><br><span class="line">        <span class="keyword">if</span>(user!=<span class="keyword">null</span>)&#123;</span><br><span class="line">            userid=user.getId().intValue();</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="comment">//Ads  处理广告   判断设备</span></span><br><span class="line">        Integer isCheckVer = <span class="number">0</span>;</span><br><span class="line">        String userAgent = request.getHeader(<span class="string">"User-Agent"</span>);</span><br><span class="line">        String version = VersionUtil.getVerionInfo(request);</span><br><span class="line">        <span class="keyword">if</span> (userAgent.contains(<span class="string">"ios"</span>)) &#123;</span><br><span class="line">            <span class="comment">//判断版本是否在审核中，获取config的ver是否等于当前版本</span></span><br><span class="line">            String key = <span class="string">"version"</span>;</span><br><span class="line">            <span class="keyword">if</span> (userAgent.contains(<span class="string">"appname:zhijianStory"</span>)) &#123;</span><br><span class="line">                key = <span class="string">"zhijianStory"</span> + <span class="string">"_version"</span>;</span><br><span class="line">            &#125;</span><br><span class="line">            Config config = <span class="keyword">this</span>.configService.getConfigByKey(key);</span><br><span class="line">            <span class="keyword">if</span> (version.compareTo(config.getVal()) == <span class="number">0</span>) &#123;</span><br><span class="line">                isCheckVer = <span class="number">1</span>;</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">        String channel = request.getHeader(<span class="string">"channel"</span>);</span><br><span class="line">        String platform = VersionUtil.getPlatformStr(request);</span><br><span class="line">        List&lt;Ads&gt; adsList=adsService.getAds(<span class="number">0</span>,<span class="number">8</span>,isCheckVer,channel,platform,ver,user);</span><br><span class="line">        <span class="keyword">if</span>(user != <span class="keyword">null</span> &amp;&amp; user.getIsTest().equals(<span class="number">1</span>))&#123;</span><br><span class="line">            List&lt;Ads&gt; adsTestList = adsService.getTestAds();</span><br><span class="line">            List&lt;Ads&gt; newAdsList = <span class="keyword">new</span> ArrayList&lt;&gt;(adsList);</span><br><span class="line">            newAdsList.addAll(adsTestList);</span><br><span class="line">            adsList=newAdsList;</span><br><span class="line">        &#125;</span><br><span class="line">        response.setAds(adsList);</span><br><span class="line">        <span class="comment">//精品推荐</span></span><br><span class="line">        Ads ads = <span class="keyword">new</span> Ads();</span><br><span class="line">        ads.setTitle(<span class="string">"精品推荐"</span>);</span><br><span class="line">        ads.setContent(<span class="string">"精品推荐"</span>);</span><br><span class="line">        ads.setUrl(<span class="string">"www.baidu.com"</span>);</span><br><span class="line">        ads.setImgPath(<span class="string">"recommend.png"</span>);</span><br><span class="line">        ads.setIcon(<span class="string">"recommend.png"</span>);</span><br><span class="line">        ads.setId(<span class="number">0L</span>);</span><br><span class="line">        ads.setTargetValue(<span class="number">0</span>);</span><br><span class="line">        ads.setTargetType(<span class="number">0</span>);</span><br><span class="line">        ads.setStatus(<span class="number">0</span>);</span><br><span class="line">        ads.setOrderBy(<span class="number">0</span>);</span><br><span class="line">        ads.setCreateTime(<span class="keyword">new</span> Date());</span><br><span class="line">        ads.setIsIosVisual(<span class="number">0</span>);</span><br><span class="line">        ads.setAdsPosition(<span class="number">0</span>);</span><br><span class="line"></span><br><span class="line">        CustomGroup recommendGroup = <span class="keyword">new</span> CustomGroup();</span><br><span class="line">        recommendGroup.setId(<span class="number">1005L</span>);</span><br><span class="line">        recommendGroup.setName(<span class="string">"精品推荐"</span>);</span><br><span class="line">        recommendGroup.setContent(<span class="string">"精品推荐"</span>);</span><br><span class="line">        recommendGroup.setIcon(<span class="string">""</span>);</span><br><span class="line">        recommendGroup.setPadIcon(<span class="string">""</span>);</span><br><span class="line">        recommendGroup.setTargetType(StoryGroupStyle.RECOMMEND.getTargetType());</span><br><span class="line">        recommendGroup.setTargetValue(<span class="number">0</span>);</span><br><span class="line">        recommendGroup.setIsSubscribe(<span class="number">0</span>);</span><br><span class="line">        recommendGroup.setAds(ads);</span><br><span class="line">        response.setRecommendGroup(recommendGroup);</span><br><span class="line"></span><br><span class="line">        <span class="comment">//最新故事 groupId  1 互动故事 2 益智游戏 3 限时免费 4 精品课程  5 系列故事  6 睡前故事  7 热销故事 8 音频 9 经典故事</span></span><br><span class="line">        <span class="comment">//10 情感教育  11 幽默故事  12 创意思维 13 小程序试看  14 传统文化 16 飞船电台  17 最新故事</span></span><br><span class="line"></span><br><span class="line">        <span class="comment">//最新故事</span></span><br><span class="line">        List&lt;DisplayGroup&gt; newStoryList = <span class="keyword">new</span> ArrayList&lt;&gt;();</span><br><span class="line">        DisplayGroup newSoryGroup = displayGroupService.getGroupById(<span class="number">17L</span>);</span><br><span class="line">        Page&lt;Story&gt; storyPage17 = groupRelevanceService.getNewGroupStoryList(user, <span class="number">17</span>, <span class="number">0</span>, <span class="number">6</span>);</span><br><span class="line">        newSoryGroup.setStorys(storyPage17.getContent());</span><br><span class="line">        newStoryList.add(newSoryGroup);</span><br><span class="line">        response.setNewStoryGroup(newStoryList);</span><br><span class="line">        <span class="comment">//精品课程</span></span><br><span class="line">        LessonIndex lessonIndex = <span class="keyword">new</span> LessonIndex();</span><br><span class="line">        lessonIndex.setName(<span class="string">"精品阅读课"</span>);</span><br><span class="line">        lessonIndex.setContent(<span class="string">"精品阅读课"</span>);</span><br><span class="line">        lessonIndex.setTargetType(StoryGroupStyle.LESSON.getTargetType());</span><br><span class="line">        lessonIndex.setIntro(<span class="string">""</span>);</span><br><span class="line">        lessonIndex.setLessonList(lessonService.getLessonList());</span><br><span class="line">        response.setLessonIndex(lessonIndex);</span><br><span class="line">        <span class="comment">//故事足迹  故事类型 type=1 4条</span></span><br><span class="line">        <span class="keyword">if</span>(userid!=<span class="number">0</span>)&#123;</span><br><span class="line">            Page&lt;UserReadRecord&gt; readRecordPage = userReadRecordService.getReadStoryRecordByUserIdAndType(user.getId(), <span class="number">1</span>, <span class="number">0</span>, <span class="number">4</span>);</span><br><span class="line">            CustomGroup userReadRecordGroup = <span class="keyword">new</span> CustomGroup();</span><br><span class="line">            userReadRecordGroup.setId(<span class="number">1000L</span>);</span><br><span class="line">            userReadRecordGroup.setName(<span class="string">"故事足迹"</span>);</span><br><span class="line">            userReadRecordGroup.setContent(<span class="string">"故事足迹"</span>);</span><br><span class="line">            userReadRecordGroup.setIcon(<span class="string">""</span>);</span><br><span class="line">            userReadRecordGroup.setPadIcon(<span class="string">""</span>);</span><br><span class="line">            userReadRecordGroup.setIsSubscribe(<span class="number">0</span>);</span><br><span class="line">            userReadRecordGroup.setTargetType(StoryGroupStyle.RECORD.getTargetType());</span><br><span class="line">            userReadRecordGroup.setTargetValue(<span class="number">0</span>);</span><br><span class="line">            userReadRecordGroup.setUserReadRecordList(readRecordPage.getContent());</span><br><span class="line">            List&lt;Story&gt; storys = <span class="keyword">new</span> ArrayList&lt;&gt;();</span><br><span class="line">            <span class="keyword">for</span> (UserReadRecord s:readRecordPage.getContent()) &#123;</span><br><span class="line">                storys.add(s.getStory());</span><br><span class="line">            &#125;</span><br><span class="line">            userReadRecordGroup.setStorys(storys);</span><br><span class="line">            response.setUserReadRecordGroup(userReadRecordGroup);</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="comment">//飞船电台</span></span><br><span class="line">        List&lt;Story&gt; radioList = storyService.getRadioList();</span><br><span class="line"><span class="comment">//        RadioGroup radioGroup = new RadioGroup();</span></span><br><span class="line">        CustomGroup radioGroup = <span class="keyword">new</span> CustomGroup();</span><br><span class="line">        radioGroup.setId(<span class="number">1004L</span>);</span><br><span class="line">        radioGroup.setName(<span class="string">"飞船电台"</span>);</span><br><span class="line">        radioGroup.setContent(<span class="string">"飞船电台"</span>);</span><br><span class="line">        radioGroup.setIcon(<span class="string">""</span>);</span><br><span class="line">        radioGroup.setPadIcon(<span class="string">""</span>);</span><br><span class="line">        radioGroup.setTargetType(StoryGroupStyle.AUDIO.getTargetType());</span><br><span class="line">        radioGroup.setTargetValue(<span class="number">0</span>);</span><br><span class="line">        radioGroup.setIsSubscribe(<span class="number">0</span>);</span><br><span class="line">        radioGroup.setStorys(radioList);</span><br><span class="line">        response.setRadioGroup(radioGroup);</span><br><span class="line">        <span class="comment">//IP专区</span></span><br><span class="line">        Page&lt;SerialStory&gt; ipStoryPage = serialStoryService.getCommonSerialStoryPage((<span class="keyword">long</span>)userid, SerialStoryStyle.IP_STORY_SERIAL, <span class="number">0</span>,<span class="number">3</span>);</span><br><span class="line">        List&lt;SerialStory&gt; ipStoryList = ipStoryPage.getContent();</span><br><span class="line">        <span class="keyword">for</span>(SerialStory item : ipStoryList)&#123;</span><br><span class="line">            serialStoryService.setSerialStoryIsBuy(user,item);</span><br><span class="line">        &#125;</span><br><span class="line">        CustomGroup ipSerialGroup = <span class="keyword">new</span> CustomGroup();</span><br><span class="line">        ipSerialGroup.setId(<span class="number">1002L</span>);</span><br><span class="line">        ipSerialGroup.setName(<span class="string">"IP专区"</span>);</span><br><span class="line">        ipSerialGroup.setContent(<span class="string">"IP专区"</span>);</span><br><span class="line">        ipSerialGroup.setIcon(<span class="string">""</span>);</span><br><span class="line">        ipSerialGroup.setPadIcon(<span class="string">""</span>);</span><br><span class="line">        ipSerialGroup.setIsSubscribe(<span class="number">0</span>);</span><br><span class="line">        ipSerialGroup.setTargetType(StoryGroupStyle.SERIAL.getTargetType());</span><br><span class="line">        ipSerialGroup.setTargetValue(<span class="number">0</span>);</span><br><span class="line">        ipSerialGroup.setSerialStories(ipStoryList);</span><br><span class="line">        response.setIpStoryGroup(ipSerialGroup);</span><br><span class="line"></span><br><span class="line">        <span class="comment">//经典故事9 &amp;创意思维12</span></span><br><span class="line">        List&lt;DisplayGroup&gt; classicAndCreateGroup = <span class="keyword">new</span> ArrayList&lt;&gt;();</span><br><span class="line">        DisplayGroup classicGroup = displayGroupService.getGroupById(<span class="number">9L</span>);</span><br><span class="line">        DisplayGroup createGroup =  displayGroupService.getGroupById(<span class="number">12L</span>);</span><br><span class="line">        Page&lt;Story&gt; storyPage9 = groupRelevanceService.getNewGroupStoryList(user, <span class="number">9</span>, <span class="number">0</span>, <span class="number">6</span>);</span><br><span class="line">        Page&lt;Story&gt; storyPage12 = groupRelevanceService.getNewGroupStoryList(user, <span class="number">12</span>, <span class="number">0</span>, <span class="number">6</span>);</span><br><span class="line">        classicGroup.setStorys(storyPage9.getContent());</span><br><span class="line">        createGroup.setStorys(storyPage12.getContent());</span><br><span class="line">        classicAndCreateGroup.add(classicGroup);</span><br><span class="line">        classicAndCreateGroup.add(createGroup);</span><br><span class="line">        response.setClassicAndCreateGroup(classicAndCreateGroup);</span><br><span class="line">        <span class="comment">//绘本丛书</span></span><br><span class="line">        Page&lt;SerialStory&gt; serialStoryPage = serialStoryService.getCommonSerialStoryPage((<span class="keyword">long</span>)userid, SerialStoryStyle.INDEX_SERIAL, <span class="number">0</span>,<span class="number">3</span>);</span><br><span class="line">        List&lt;SerialStory&gt; serialStoryList = serialStoryPage.getContent();</span><br><span class="line">        <span class="keyword">for</span>(SerialStory item : serialStoryList)&#123;</span><br><span class="line">            serialStoryService.setSerialStoryIsBuy(user,item);</span><br><span class="line">        &#125;</span><br><span class="line">        response.setSerialStoryCount(<span class="number">3</span>);</span><br><span class="line">        CustomGroup huiBenGroup = <span class="keyword">new</span> CustomGroup();</span><br><span class="line">        huiBenGroup.setId(<span class="number">1000L</span>);</span><br><span class="line">        huiBenGroup.setName(<span class="string">"绘本丛书"</span>);</span><br><span class="line">        huiBenGroup.setContent(<span class="string">"绘本丛书"</span>);</span><br><span class="line">        huiBenGroup.setIcon(<span class="string">""</span>);</span><br><span class="line">        huiBenGroup.setPadIcon(<span class="string">""</span>);</span><br><span class="line">        huiBenGroup.setIsSubscribe(<span class="number">0</span>);</span><br><span class="line">        huiBenGroup.setTargetType(StoryGroupStyle.SERIAL.getTargetType());</span><br><span class="line">        huiBenGroup.setTargetValue(<span class="number">0</span>);</span><br><span class="line">        huiBenGroup.setSerialStories(serialStoryList);</span><br><span class="line">        response.setSerialGroup(huiBenGroup);</span><br><span class="line"></span><br><span class="line">        <span class="comment">//情感教育10 &amp;幽默故事11</span></span><br><span class="line">        List&lt;DisplayGroup&gt; emotionAndHumourGroup= <span class="keyword">new</span> ArrayList&lt;&gt;();</span><br><span class="line">        DisplayGroup emotionGroup =  displayGroupService.getGroupById(<span class="number">10L</span>);</span><br><span class="line">        DisplayGroup humourGroup =  displayGroupService.getGroupById(<span class="number">11L</span>);</span><br><span class="line">        Page&lt;Story&gt; storyPage10 = groupRelevanceService.getNewGroupStoryList(user, <span class="number">10</span>, <span class="number">0</span>, <span class="number">6</span>);</span><br><span class="line">        Page&lt;Story&gt; storyPage11 = groupRelevanceService.getNewGroupStoryList(user, <span class="number">11</span>, <span class="number">0</span>, <span class="number">6</span>);</span><br><span class="line">        emotionGroup.setStorys(storyPage10.getContent());</span><br><span class="line">        humourGroup.setStorys(storyPage11.getContent());</span><br><span class="line">        emotionAndHumourGroup.add(emotionGroup);</span><br><span class="line">        emotionAndHumourGroup.add(humourGroup);</span><br><span class="line">        response.setEmotionAndHumourGroup(emotionAndHumourGroup);</span><br><span class="line">        <span class="comment">//益智训练专区</span></span><br><span class="line">        GetSerialStoryPageResponse smartGameSerialStoryResponse = serialStoryController.getSmartGameSerialStoryPage(ssToken, SerialStoryStyle.SMART_GAME_SERIAL.getId(), <span class="number">1</span>, <span class="number">3</span>);</span><br><span class="line">        CustomGroup gameSerialGroup = <span class="keyword">new</span> CustomGroup();</span><br><span class="line">        gameSerialGroup.setId(<span class="number">1003L</span>);</span><br><span class="line">        gameSerialGroup.setName(<span class="string">"益智训练专区"</span>);</span><br><span class="line">        gameSerialGroup.setContent(<span class="string">"益智训练专区"</span>);</span><br><span class="line">        gameSerialGroup.setIcon(<span class="string">""</span>);</span><br><span class="line">        gameSerialGroup.setPadIcon(<span class="string">""</span>);</span><br><span class="line">        gameSerialGroup.setTargetValue(<span class="number">0</span>);</span><br><span class="line">        gameSerialGroup.setIsSubscribe(<span class="number">0</span>);</span><br><span class="line">        gameSerialGroup.setTargetType(StoryGroupStyle.SERIAL.getTargetType());</span><br><span class="line">        gameSerialGroup.setTargetValue(<span class="number">0</span>);</span><br><span class="line">        gameSerialGroup.setSerialStories(smartGameSerialStoryResponse.getSerialStoryList());</span><br><span class="line">        response.setGameSerialGroup(gameSerialGroup);</span><br><span class="line"></span><br><span class="line">        <span class="comment">//传统文化14</span></span><br><span class="line">        List&lt;DisplayGroup&gt; traditionCultureGroupList = <span class="keyword">new</span> ArrayList&lt;&gt;();</span><br><span class="line">        DisplayGroup traditionCultureGroup =  displayGroupService.getGroupById(<span class="number">14L</span>);</span><br><span class="line">        Page&lt;Story&gt; storyPage14 = groupRelevanceService.getNewGroupStoryList(user, <span class="number">14</span>, <span class="number">0</span>, <span class="number">6</span>);</span><br><span class="line">        traditionCultureGroup.setStorys(storyPage14.getContent());</span><br><span class="line">        traditionCultureGroupList.add(traditionCultureGroup);</span><br><span class="line">        response.setTraditionCultureGroup(traditionCultureGroupList);</span><br><span class="line">        <span class="comment">//其他分类 暂无</span></span><br><span class="line"></span><br><span class="line">        <span class="comment">//Prompt</span></span><br><span class="line">        Prompt prompt = <span class="keyword">new</span> Prompt(PromptStyle.STUDY_PLAN.getId(),PromptStyle.STUDY_PLAN.getName(),PromptStyle.STUDY_PLAN.getUrl());</span><br><span class="line">        <span class="keyword">if</span>(userid!=<span class="number">0</span>)&#123;</span><br><span class="line">            <span class="keyword">try</span> &#123;</span><br><span class="line">                prompt = promptService.getPrompt(userid);</span><br><span class="line">            &#125;<span class="keyword">catch</span> (Exception e)&#123;</span><br><span class="line">                e.printStackTrace();</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">        response.setPrompt(prompt);</span><br><span class="line">        <span class="comment">//isSvip</span></span><br><span class="line">        <span class="keyword">if</span> (user != <span class="keyword">null</span> &amp;&amp; (user.getSvip().equals(SvipStyle.LEVEL_FOUR.getId()) || user.getSvip().equals(SvipStyle.LEVEL_THREE.getId())))&#123;</span><br><span class="line">            response.setIsSvip(<span class="number">1</span>);</span><br><span class="line">        &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">            response.setIsSvip(<span class="number">0</span>);</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">return</span> response;</span><br><span class="line">    &#125;</span><br></pre></td></tr></table></figure>
<ul>
<li>Thread controller</li>
</ul>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line"><span class="meta">@RequestMapping</span>(value = <span class="string">"sgetIndex"</span>, method = RequestMethod.GET)</span><br><span class="line">   <span class="meta">@ResponseBody</span></span><br><span class="line">   <span class="meta">@ApiOperation</span>(value = <span class="string">"首页 "</span>)</span><br><span class="line">   <span class="function">GetIndex280Response <span class="title">getIndex</span><span class="params">(</span></span></span><br><span class="line"><span class="function"><span class="params">           @RequestHeader(value = <span class="string">"ssToken"</span>, required = <span class="keyword">false</span>)</span> String ssToken,</span></span><br><span class="line"><span class="function">           @<span class="title">ApiParam</span><span class="params">(value = <span class="string">"版本号"</span>, defaultValue = <span class="string">""</span>, required = <span class="keyword">false</span>)</span> @<span class="title">RequestParam</span><span class="params">(required = <span class="keyword">false</span>, defaultValue = <span class="string">""</span>)</span> String ver</span></span><br><span class="line"><span class="function">   )</span>&#123;</span><br><span class="line">    </span><br><span class="line">       <span class="comment">//使用线程增加故事</span></span><br><span class="line">       <span class="keyword">final</span> ThreadPoolExecutor executor = (ThreadPoolExecutor) Executors.newFixedThreadPool(<span class="number">15</span>);</span><br><span class="line">    </span><br><span class="line">       <span class="comment">/**</span></span><br><span class="line"><span class="comment">        * 线程集合</span></span><br><span class="line"><span class="comment">        */</span></span><br><span class="line">       ThreadResult threadResult=<span class="keyword">new</span> ThreadResult();</span><br><span class="line">       Long loginId=(Long)request.getAttribute(<span class="string">"loginId"</span>);</span><br><span class="line">       User user=userService.getUser(loginId.intValue());</span><br><span class="line">       logger.info(<span class="string">"-------------begin"</span>);</span><br><span class="line">       GetIndex280Response response = <span class="keyword">this</span>.getIndex280(user, <span class="number">3</span>,threadResult);</span><br><span class="line">    </span><br><span class="line">       logger.info(<span class="string">"-------------3"</span>);</span><br><span class="line">       threadResult.groupPromptThread=<span class="keyword">new</span> GroupPromptThread(promptService,user);</span><br><span class="line">       response=<span class="keyword">this</span>.responseSetThreadValue2(response,executor,threadResult);</span><br><span class="line">       logger.info(<span class="string">"-------------end resp"</span>);</span><br><span class="line">       <span class="keyword">return</span> response;</span><br><span class="line">   &#125;</span><br></pre></td></tr></table></figure>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br><span class="line">150</span><br><span class="line">151</span><br><span class="line">152</span><br><span class="line">153</span><br><span class="line">154</span><br><span class="line">155</span><br><span class="line">156</span><br><span class="line">157</span><br><span class="line">158</span><br><span class="line">159</span><br><span class="line">160</span><br><span class="line">161</span><br><span class="line">162</span><br><span class="line">163</span><br><span class="line">164</span><br><span class="line">165</span><br><span class="line">166</span><br><span class="line">167</span><br><span class="line">168</span><br><span class="line">169</span><br><span class="line">170</span><br><span class="line">171</span><br><span class="line">172</span><br><span class="line">173</span><br><span class="line">174</span><br><span class="line">175</span><br><span class="line">176</span><br><span class="line">177</span><br><span class="line">178</span><br><span class="line">179</span><br><span class="line">180</span><br><span class="line">181</span><br><span class="line">182</span><br><span class="line">183</span><br><span class="line">184</span><br><span class="line">185</span><br><span class="line">186</span><br><span class="line">187</span><br><span class="line">188</span><br><span class="line">189</span><br><span class="line">190</span><br><span class="line">191</span><br><span class="line">192</span><br><span class="line">193</span><br><span class="line">194</span><br><span class="line">195</span><br><span class="line">196</span><br><span class="line">197</span><br><span class="line">198</span><br><span class="line">199</span><br><span class="line">200</span><br><span class="line">201</span><br><span class="line">202</span><br><span class="line">203</span><br><span class="line">204</span><br></pre></td><td class="code"><pre><span class="line">  <span class="function"><span class="keyword">private</span> GetIndex280Response <span class="title">getIndex280</span><span class="params">(User user, Integer serialPageSize,ThreadResult threadResult)</span> </span>&#123;</span><br><span class="line"></span><br><span class="line">        GetIndex280Response response = <span class="keyword">new</span> GetIndex280Response();</span><br><span class="line">        <span class="comment">//判断svip</span></span><br><span class="line">        <span class="keyword">if</span>(user != <span class="keyword">null</span> &amp;&amp;(user.getSvip().equals(SvipStyle.LEVEL_FOUR.getId()) || user.getSvip().equals(SvipStyle.LEVEL_THREE.getId())))&#123;</span><br><span class="line">            response.setIsSvip(<span class="number">1</span>);</span><br><span class="line">        &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">            response.setIsSvip(<span class="number">0</span>);</span><br><span class="line">        &#125;</span><br><span class="line">        logger.info(<span class="string">"-------------001"</span>);</span><br><span class="line">        <span class="comment">//判断设备</span></span><br><span class="line">        Integer isCheckVer = <span class="number">0</span>;</span><br><span class="line">        String userAgent = request.getHeader(<span class="string">"User-Agent"</span>);</span><br><span class="line">        <span class="keyword">if</span> (userAgent.contains(<span class="string">"ios"</span>)) &#123;</span><br><span class="line">            <span class="comment">//判断版本是否在审核中，获取config的ver是否等于当前版本</span></span><br><span class="line">            String key = <span class="string">"version"</span>;</span><br><span class="line">            <span class="keyword">if</span>(userAgent.contains(<span class="string">"appname:zhijianStory"</span>))&#123;</span><br><span class="line">                key = <span class="string">"zhijianStory"</span>+<span class="string">"_version"</span>;</span><br><span class="line">            &#125;</span><br><span class="line">            Config config=<span class="keyword">this</span>.configService.getConfigByKey(key);</span><br><span class="line">            String ver = VersionUtil.getVerionInfo(request);</span><br><span class="line">            <span class="keyword">if</span>(ver.compareTo(config.getVal()) == <span class="number">0</span>)&#123;</span><br><span class="line">                isCheckVer = <span class="number">1</span>;</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">        logger.info(<span class="string">"-------------0011"</span>);</span><br><span class="line">        <span class="comment">//处理广告</span></span><br><span class="line">        String channel = request.getHeader(<span class="string">"channel"</span>);</span><br><span class="line">        String platform= VersionUtil.getPlatformStr(request);</span><br><span class="line">        String ver=VersionUtil.getVerionInfo(request);</span><br><span class="line">        threadResult.groupAdThread=<span class="keyword">new</span> GroupAdThread(adsService,channel,platform,isCheckVer,ver,user);</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">        logger.info(<span class="string">"-------------0016"</span>);</span><br><span class="line">        <span class="comment">//精品推荐</span></span><br><span class="line">        Ads ads = <span class="keyword">new</span> Ads();</span><br><span class="line">        ads.setTitle(<span class="string">"精品推荐"</span>);</span><br><span class="line">        ads.setContent(<span class="string">"精品推荐"</span>);</span><br><span class="line">        ads.setUrl(<span class="string">"www.baidu.com"</span>);</span><br><span class="line">        ads.setImgPath(<span class="string">"recommend.png"</span>);</span><br><span class="line">        ads.setIcon(<span class="string">"recommend.png"</span>);</span><br><span class="line">        ads.setId(<span class="number">0L</span>);</span><br><span class="line">        ads.setTargetValue(<span class="number">0</span>);</span><br><span class="line">        ads.setTargetType(<span class="number">0</span>);</span><br><span class="line">        ads.setStatus(<span class="number">0</span>);</span><br><span class="line">        ads.setOrderBy(<span class="number">0</span>);</span><br><span class="line">        ads.setCreateTime(<span class="keyword">new</span> Date());</span><br><span class="line">        ads.setIsIosVisual(<span class="number">0</span>);</span><br><span class="line">        ads.setAdsPosition(<span class="number">0</span>);</span><br><span class="line"></span><br><span class="line">        CustomGroup recommendGroup = <span class="keyword">new</span> CustomGroup();</span><br><span class="line">        recommendGroup.setId(<span class="number">1006L</span>);</span><br><span class="line">        recommendGroup.setName(<span class="string">"精品推荐"</span>);</span><br><span class="line">        recommendGroup.setContent(<span class="string">"精品推荐"</span>);</span><br><span class="line">        recommendGroup.setIcon(<span class="string">""</span>);</span><br><span class="line">        recommendGroup.setPadIcon(<span class="string">""</span>);</span><br><span class="line">        recommendGroup.setTargetType(StoryGroupStyle.RECOMMEND.getTargetType());</span><br><span class="line">        recommendGroup.setTargetValue(<span class="number">0</span>);</span><br><span class="line">        recommendGroup.setIsSubscribe(<span class="number">0</span>);</span><br><span class="line">        recommendGroup.setAds(ads);</span><br><span class="line">        response.setRecommendGroup(recommendGroup);</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">        logger.info(<span class="string">"-------------00113"</span>);</span><br><span class="line">        <span class="keyword">if</span>(user!=<span class="keyword">null</span> &amp;&amp; user.getId()!=<span class="number">0</span>)&#123;</span><br><span class="line">            Page&lt;UserReadRecord&gt; readRecordPage = userReadRecordService.getReadStoryRecordByUserIdAndType(user.getId(), <span class="number">1</span>, <span class="number">0</span>, <span class="number">4</span>);</span><br><span class="line">            CustomGroup userReadRecordGroup = <span class="keyword">new</span> CustomGroup();</span><br><span class="line">            userReadRecordGroup.setId(<span class="number">1004L</span>);</span><br><span class="line">            userReadRecordGroup.setName(<span class="string">"故事足迹"</span>);</span><br><span class="line">            userReadRecordGroup.setContent(<span class="string">"故事足迹"</span>);</span><br><span class="line">            userReadRecordGroup.setIcon(<span class="string">""</span>);</span><br><span class="line">            userReadRecordGroup.setPadIcon(<span class="string">""</span>);</span><br><span class="line">            userReadRecordGroup.setIsSubscribe(<span class="number">0</span>);</span><br><span class="line">            userReadRecordGroup.setTargetType(StoryGroupStyle.STORY.getTargetType());</span><br><span class="line">            userReadRecordGroup.setTargetValue(<span class="number">0</span>);</span><br><span class="line">            userReadRecordGroup.setUserReadRecordList(readRecordPage.getContent());</span><br><span class="line">            List&lt;Story&gt; storys = <span class="keyword">new</span> ArrayList&lt;&gt;();</span><br><span class="line">            <span class="keyword">for</span> (UserReadRecord s:readRecordPage.getContent()) &#123;</span><br><span class="line">                storys.add(s.getStory());</span><br><span class="line">            &#125;</span><br><span class="line">            userReadRecordGroup.setStorys(storys);</span><br><span class="line">            response.setUserReadRecordGroup(userReadRecordGroup);</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="comment">//飞船电台</span></span><br><span class="line">        List&lt;Story&gt; radioList = storyService.getRadioList();</span><br><span class="line">        CustomGroup radioGroup = <span class="keyword">new</span> CustomGroup();</span><br><span class="line">        radioGroup.setId(<span class="number">1005L</span>);</span><br><span class="line">        radioGroup.setName(<span class="string">"飞船电台"</span>);</span><br><span class="line">        radioGroup.setContent(<span class="string">"飞船电台"</span>);</span><br><span class="line">        radioGroup.setIcon(<span class="string">""</span>);</span><br><span class="line">        radioGroup.setPadIcon(<span class="string">""</span>);</span><br><span class="line">        radioGroup.setTargetType(StoryGroupStyle.AUDIO.getTargetType());</span><br><span class="line">        radioGroup.setTargetValue(<span class="number">0</span>);</span><br><span class="line">        radioGroup.setIsSubscribe(<span class="number">0</span>);</span><br><span class="line">        radioGroup.setStorys(radioList);</span><br><span class="line">        response.setRadioGroup(radioGroup);</span><br><span class="line"></span><br><span class="line">        logger.info(<span class="string">"-------------0010"</span>);</span><br><span class="line">        LessonIndex lessonIndex = <span class="keyword">new</span> LessonIndex();</span><br><span class="line">        lessonIndex.setName(<span class="string">"精品课程"</span>);</span><br><span class="line">        lessonIndex.setContent(<span class="string">"精品课程"</span>);</span><br><span class="line">        lessonIndex.setIntro(<span class="string">""</span>);</span><br><span class="line">        lessonIndex.setTargetType(StoryGroupStyle.LESSON.getTargetType());</span><br><span class="line">        lessonIndex.setLessonList(lessonService.getLessonList());</span><br><span class="line">        response.setLessonIndex(lessonIndex);</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">        logger.info(<span class="string">"-------益智游戏专区------003"</span>);</span><br><span class="line">        List&lt;CustomGroup&gt; cgroups = <span class="keyword">new</span> ArrayList&lt;&gt;();</span><br><span class="line">        CustomGroup gameSerialGroup = <span class="keyword">new</span> CustomGroup();</span><br><span class="line">        gameSerialGroup.setId(<span class="number">1003L</span>);</span><br><span class="line">        gameSerialGroup.setName(<span class="string">"益智游戏专区"</span>);</span><br><span class="line">        gameSerialGroup.setContent(<span class="string">"益智游戏专区"</span>);</span><br><span class="line">        gameSerialGroup.setIcon(<span class="string">""</span>);</span><br><span class="line">        gameSerialGroup.setPadIcon(<span class="string">""</span>);</span><br><span class="line">        gameSerialGroup.setIsSubscribe(<span class="number">0</span>);</span><br><span class="line">        cgroups.add(gameSerialGroup);</span><br><span class="line">        GroupSerialThread groupSerialThread3=<span class="keyword">new</span> GroupSerialThread(serialStoryService,SerialStoryStyle.SMART_GAME_SERIAL,user,<span class="number">0</span>,serialPageSize);</span><br><span class="line">        threadResult.serialThreads.add(groupSerialThread3);</span><br><span class="line"></span><br><span class="line">        logger.info(<span class="string">"-------ip专区------002"</span>);</span><br><span class="line">        CustomGroup ipSerialGroup = <span class="keyword">new</span> CustomGroup();</span><br><span class="line">        ipSerialGroup.setId(<span class="number">1002L</span>);</span><br><span class="line">        ipSerialGroup.setName(<span class="string">"ip专区"</span>);</span><br><span class="line">        ipSerialGroup.setContent(<span class="string">"ip专区"</span>);</span><br><span class="line">        ipSerialGroup.setIcon(<span class="string">""</span>);</span><br><span class="line">        ipSerialGroup.setPadIcon(<span class="string">""</span>);</span><br><span class="line">        ipSerialGroup.setIsSubscribe(<span class="number">0</span>);</span><br><span class="line">        cgroups.add(ipSerialGroup);</span><br><span class="line">        GroupSerialThread groupSerialThread2=<span class="keyword">new</span> GroupSerialThread(serialStoryService,SerialStoryStyle.IP_STORY_SERIAL,user,<span class="number">0</span>,serialPageSize);</span><br><span class="line">        threadResult.serialThreads.add(groupSerialThread2);</span><br><span class="line"></span><br><span class="line">        logger.info(<span class="string">"-------绘本丛书------000"</span>);</span><br><span class="line">        CustomGroup huiBenGroup = <span class="keyword">new</span> CustomGroup();</span><br><span class="line">        huiBenGroup.setId(<span class="number">1000L</span>);</span><br><span class="line">        huiBenGroup.setName(<span class="string">"绘本丛书"</span>);</span><br><span class="line">        huiBenGroup.setContent(<span class="string">""</span>);</span><br><span class="line">        huiBenGroup.setIcon(<span class="string">""</span>);</span><br><span class="line">        huiBenGroup.setPadIcon(<span class="string">""</span>);</span><br><span class="line">        huiBenGroup.setIsSubscribe(<span class="number">0</span>);</span><br><span class="line">        cgroups.add(huiBenGroup);</span><br><span class="line">        GroupSerialThread groupSerialThread=<span class="keyword">new</span> GroupSerialThread(serialStoryService,SerialStoryStyle.INDEX_SERIAL,user,<span class="number">0</span>,serialPageSize);</span><br><span class="line">        threadResult.serialThreads.add(groupSerialThread);</span><br><span class="line"></span><br><span class="line">        response.setSerialStoryCount(<span class="number">3</span>);</span><br><span class="line"></span><br><span class="line">        <span class="comment">//获取分组列表</span></span><br><span class="line"><span class="comment">//        List&lt;DisplayGroup&gt; displayGroups = storyService.getStoryGroupListByNewCategory();</span></span><br><span class="line">        DisplayGroup group9 = displayGroupService.getGroupById(<span class="number">9L</span>);</span><br><span class="line">        group9.setStorys(<span class="keyword">new</span> ArrayList&lt;Story&gt;());</span><br><span class="line">        DisplayGroup group12 = displayGroupService.getGroupById(<span class="number">12L</span>);</span><br><span class="line">        group12.setStorys(<span class="keyword">new</span> ArrayList&lt;Story&gt;());</span><br><span class="line">        DisplayGroup group10 = displayGroupService.getGroupById(<span class="number">10L</span>);</span><br><span class="line">        group10.setStorys(<span class="keyword">new</span> ArrayList&lt;Story&gt;());</span><br><span class="line">        DisplayGroup group11 = displayGroupService.getGroupById(<span class="number">11L</span>);</span><br><span class="line">        group11.setStorys(<span class="keyword">new</span> ArrayList&lt;Story&gt;());</span><br><span class="line">        DisplayGroup group17 = displayGroupService.getGroupById(<span class="number">17L</span>);</span><br><span class="line">        group17.setStorys(<span class="keyword">new</span> ArrayList&lt;Story&gt;());</span><br><span class="line">        DisplayGroup group14 = displayGroupService.getGroupById(<span class="number">14L</span>);</span><br><span class="line">        group14.setStorys(<span class="keyword">new</span> ArrayList&lt;Story&gt;());</span><br><span class="line"></span><br><span class="line">        response.setSerialGroup(huiBenGroup);</span><br><span class="line">        response.setGameSerialGroup(gameSerialGroup);</span><br><span class="line">        response.setIpStoryGroup(ipSerialGroup);</span><br><span class="line"></span><br><span class="line">        List&lt;DisplayGroup&gt; newStoryGroup = <span class="keyword">new</span> ArrayList&lt;&gt;();</span><br><span class="line">        newStoryGroup.add(group17);</span><br><span class="line">        List&lt;DisplayGroup&gt; classicAndCreateGroup = <span class="keyword">new</span> ArrayList&lt;&gt;();</span><br><span class="line">        classicAndCreateGroup.add(group9);</span><br><span class="line">        classicAndCreateGroup.add(group12);</span><br><span class="line">        List&lt;DisplayGroup&gt; emotionAndHumourGroup = <span class="keyword">new</span> ArrayList&lt;&gt;();</span><br><span class="line">        emotionAndHumourGroup.add(group10);</span><br><span class="line">        emotionAndHumourGroup.add(group11);</span><br><span class="line">        List&lt;DisplayGroup&gt; traditionCultureGroup = <span class="keyword">new</span> ArrayList&lt;&gt;();</span><br><span class="line">        traditionCultureGroup.add(group14);</span><br><span class="line"></span><br><span class="line">        response.setNewStoryGroup(newStoryGroup);</span><br><span class="line">        response.setClassicAndCreateGroup(classicAndCreateGroup);</span><br><span class="line">        response.setEmotionAndHumourGroup(emotionAndHumourGroup);</span><br><span class="line">        response.setTraditionCultureGroup(traditionCultureGroup);</span><br><span class="line"></span><br><span class="line">        logger.info(<span class="string">"-------------003"</span>);</span><br><span class="line">        <span class="comment">//最新故事 groupId 9 经典故事 10 情感教育  11 幽默故事  12 创意思维 14 传统文化 16 飞船电台  17 最新故事</span></span><br><span class="line">        <span class="comment">//9  12</span></span><br><span class="line">        GroupStoryThread groupStoryThread9=<span class="keyword">new</span> GroupStoryThread(groupRelevanceService,user,<span class="number">9</span>,<span class="number">0</span>,<span class="number">6</span>);</span><br><span class="line">        threadResult.storyThreads.add(groupStoryThread9);</span><br><span class="line">        GroupStoryThread groupStoryThread12=<span class="keyword">new</span> GroupStoryThread(groupRelevanceService,user,<span class="number">12</span>,<span class="number">0</span>,<span class="number">6</span>);</span><br><span class="line">        threadResult.storyThreads.add(groupStoryThread12);</span><br><span class="line">        <span class="comment">// 10  11</span></span><br><span class="line">        GroupStoryThread groupStoryThread10=<span class="keyword">new</span> GroupStoryThread(groupRelevanceService,user,<span class="number">10</span>,<span class="number">0</span>,<span class="number">6</span>);</span><br><span class="line">        threadResult.storyThreads.add(groupStoryThread10);</span><br><span class="line">        GroupStoryThread groupStoryThread11=<span class="keyword">new</span> GroupStoryThread(groupRelevanceService,user,<span class="number">11</span>,<span class="number">0</span>,<span class="number">6</span>);</span><br><span class="line">        threadResult.storyThreads.add(groupStoryThread11);</span><br><span class="line">        <span class="comment">// 17</span></span><br><span class="line">        GroupStoryThread groupStoryThread17=<span class="keyword">new</span> GroupStoryThread(groupRelevanceService,user,<span class="number">17</span>,<span class="number">0</span>,<span class="number">6</span>);</span><br><span class="line">        threadResult.storyThreads.add(groupStoryThread17);</span><br><span class="line">        <span class="comment">// 14</span></span><br><span class="line">        GroupStoryThread groupStoryThread14=<span class="keyword">new</span> GroupStoryThread(groupRelevanceService,user,<span class="number">14</span>,<span class="number">0</span>,<span class="number">6</span>);</span><br><span class="line">        threadResult.storyThreads.add(groupStoryThread14);</span><br><span class="line"></span><br><span class="line">        logger.info(<span class="string">"-------------004"</span>);</span><br><span class="line"></span><br><span class="line">        <span class="keyword">return</span> response;</span><br><span class="line">    &#125;</span><br></pre></td></tr></table></figure>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">private</span> GetIndex280Response <span class="title">responseSetThreadValue2</span><span class="params">(GetIndex280Response response, ExecutorService executor, ThreadResult threadResult)</span></span>&#123;</span><br><span class="line">        logger.info(<span class="string">"=====1"</span>);</span><br><span class="line">        <span class="keyword">for</span>(GroupStoryThread groupStoryThreadItem:threadResult.storyThreads)&#123;</span><br><span class="line">            executor.execute(groupStoryThreadItem);</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        executor.execute(threadResult.groupAdThread);</span><br><span class="line">        <span class="keyword">for</span>(GroupSerialThread groupSerialThread:threadResult.serialThreads)&#123;</span><br><span class="line">            executor.execute(groupSerialThread);</span><br><span class="line">        &#125;</span><br><span class="line">        executor.execute(threadResult.groupAdThread);</span><br><span class="line">        <span class="keyword">if</span>(threadResult.groupPromptThread!=<span class="keyword">null</span>)&#123;</span><br><span class="line">            executor.execute(threadResult.groupPromptThread);</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        logger.info(<span class="string">"=====2"</span>);</span><br><span class="line">        <span class="keyword">try</span> &#123;</span><br><span class="line">            executor.shutdown();</span><br><span class="line">            executor.awaitTermination(<span class="number">5</span>, TimeUnit.SECONDS);</span><br><span class="line">        &#125; <span class="keyword">catch</span> (InterruptedException ignored) &#123;</span><br><span class="line">            ignored.printStackTrace();</span><br><span class="line">        &#125;</span><br><span class="line">        logger.info(<span class="string">"=====3"</span>);</span><br><span class="line">        <span class="comment">//最新故事 groupId  1 互动故事 2 益智游戏 3 限时免费 4 精品课程  5 系列故事  6 睡前故事  7 热销故事 8 音频 9 经典故事</span></span><br><span class="line">        <span class="comment">//10 情感教育  11 幽默故事  12 创意思维 13 小程序试看  14 传统文化 16 飞船电台  17 最新故事</span></span><br><span class="line">        <span class="comment">//赋值</span></span><br><span class="line">        <span class="keyword">for</span>(GroupStoryThread groupStoryThread1:threadResult.storyThreads)&#123;</span><br><span class="line"><span class="comment">//            if(groupStoryThread1.getGroupId()==3)&#123;</span></span><br><span class="line"><span class="comment">//                response.getGroups().get(0).setStorys(groupStoryThread1.getStoryPage().getContent());</span></span><br><span class="line"><span class="comment">//            &#125;</span></span><br><span class="line">            <span class="comment">// 9经典故事  12创意思维</span></span><br><span class="line">            <span class="keyword">if</span>(groupStoryThread1.getGroupId()==<span class="number">9</span>)&#123;</span><br><span class="line">                response.getClassicAndCreateGroup().get(<span class="number">0</span>).setStorys(groupStoryThread1.getStoryPage().getContent());</span><br><span class="line">            &#125;</span><br><span class="line">            <span class="keyword">if</span>(groupStoryThread1.getGroupId()==<span class="number">12</span>)&#123;</span><br><span class="line">                response.getClassicAndCreateGroup().get(<span class="number">1</span>).setStorys(groupStoryThread1.getStoryPage().getContent());</span><br><span class="line">            &#125;</span><br><span class="line">            <span class="comment">//10 情感教育  11 幽默故事</span></span><br><span class="line">            <span class="keyword">if</span>(groupStoryThread1.getGroupId()==<span class="number">10</span>)&#123;</span><br><span class="line">                response.getEmotionAndHumourGroup().get(<span class="number">0</span>).setStorys(groupStoryThread1.getStoryPage().getContent());</span><br><span class="line">            &#125;</span><br><span class="line">            <span class="keyword">if</span>(groupStoryThread1.getGroupId()==<span class="number">11</span>)&#123;</span><br><span class="line">                response.getEmotionAndHumourGroup().get(<span class="number">1</span>).setStorys(groupStoryThread1.getStoryPage().getContent());</span><br><span class="line">            &#125;</span><br><span class="line">            <span class="comment">// 17最新故事</span></span><br><span class="line">            <span class="keyword">if</span>(groupStoryThread1.getGroupId()==<span class="number">17</span>)&#123;</span><br><span class="line">                response.getNewStoryGroup().get(<span class="number">0</span>).setStorys(groupStoryThread1.getStoryPage().getContent());</span><br><span class="line">            &#125;</span><br><span class="line"><span class="comment">//            for(DisplayGroup displayGroup:response.getGroupList())&#123;</span></span><br><span class="line"><span class="comment">//                if(groupStoryThread1.getGroupId()==displayGroup.getId().intValue())&#123;</span></span><br><span class="line"><span class="comment">//                    if(displayGroup==null)&#123;</span></span><br><span class="line"><span class="comment">//                        continue;</span></span><br><span class="line"><span class="comment">//                    &#125;</span></span><br><span class="line"><span class="comment">//                    displayGroup.setStorys(groupStoryThread1.getStoryPage().getContent());</span></span><br><span class="line"><span class="comment">//                &#125;</span></span><br><span class="line"><span class="comment">//            &#125;</span></span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">for</span>(GroupSerialThread groupSerialThread:threadResult.serialThreads)&#123;</span><br><span class="line">            <span class="comment">//绘本</span></span><br><span class="line">            <span class="keyword">if</span>(response.getSerialGroup().getId()==<span class="number">1000L</span>&amp;&amp;groupSerialThread.getSerialStoryStyle()==SerialStoryStyle.INDEX_SERIAL)&#123;</span><br><span class="line">                response.getSerialGroup().setSerialStories(groupSerialThread.getSerialStoryList());</span><br><span class="line">            &#125;</span><br><span class="line">            <span class="comment">//IP专区</span></span><br><span class="line">            <span class="keyword">if</span>(response.getIpStoryGroup().getId()==<span class="number">1002L</span>&amp;&amp;groupSerialThread.getSerialStoryStyle()==SerialStoryStyle.IP_STORY_SERIAL)&#123;</span><br><span class="line">                response.getIpStoryGroup().setSerialStories(groupSerialThread.getSerialStoryList());</span><br><span class="line">            &#125;</span><br><span class="line">            <span class="comment">//益智专区</span></span><br><span class="line">            <span class="keyword">if</span>(response.getGameSerialGroup().getId()==<span class="number">1003L</span>&amp;&amp;groupSerialThread.getSerialStoryStyle()==SerialStoryStyle.SMART_GAME_SERIAL)&#123;</span><br><span class="line">                response.getGameSerialGroup().setSerialStories(groupSerialThread.getSerialStoryList());</span><br><span class="line">            &#125;</span><br><span class="line"><span class="comment">//            for(CustomGroup customGroup:response.getGroups())&#123;</span></span><br><span class="line"><span class="comment">//                if(customGroup.getId()==1000L&amp;&amp;groupSerialThread.getSerialStoryStyle()==SerialStoryStyle.INDEX_SERIAL)&#123;</span></span><br><span class="line"><span class="comment">//                    customGroup.setSerialStories(groupSerialThread.getSerialStoryList());</span></span><br><span class="line"><span class="comment">//                &#125;</span></span><br><span class="line"><span class="comment">//                if(customGroup.getId()==1002L&amp;&amp;groupSerialThread.getSerialStoryStyle()==SerialStoryStyle.IP_STORY_SERIAL)&#123;</span></span><br><span class="line"><span class="comment">//                    customGroup.setSerialStories(groupSerialThread.getSerialStoryList());</span></span><br><span class="line"><span class="comment">//                &#125;</span></span><br><span class="line"><span class="comment">//                if(customGroup.getId()==1003L&amp;&amp;groupSerialThread.getSerialStoryStyle()==SerialStoryStyle.SUBJECT_SERIAL)&#123;</span></span><br><span class="line"><span class="comment">//                    customGroup.setSerialStories(groupSerialThread.getSerialStoryList());</span></span><br><span class="line"><span class="comment">//                &#125;</span></span><br><span class="line"><span class="comment">//            &#125;</span></span><br><span class="line">        &#125;</span><br><span class="line">        response.setAds(threadResult.groupAdThread.getAdsList());</span><br><span class="line">        <span class="keyword">if</span>(threadResult.groupPromptThread!=<span class="keyword">null</span>)&#123;</span><br><span class="line">            response.setPrompt(threadResult.groupPromptThread.getPrompt());</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        logger.info(<span class="string">"=====4"</span>);</span><br><span class="line">        <span class="keyword">return</span> response;</span><br><span class="line">    &#125;</span><br></pre></td></tr></table></figure>
      
    </div>
    <footer class="article-footer">
      <a data-url="http://yoursite.com/2018/11/05/多线程查询/" data-id="ckcc5iwly0047q4uwzdx2b6cs" class="article-share-link">Teilen</a>
      
      
  <ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/线程/">线程</a></li></ul>

    </footer>
  </div>
  
</article>


  
    <article id="post-Exceutor" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-meta">
    <a href="/2018/11/05/Exceutor/" class="article-date">
  <time datetime="2018-11-05T02:20:26.000Z" itemprop="datePublished">2018-11-05</time>
</a>
    
  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 itemprop="name">
      <a class="article-title" href="/2018/11/05/Exceutor/">Exceutor</a>
    </h1>
  

      </header>
    
    <div class="article-entry" itemprop="articleBody">
      
        <h5 id="Executor"><a href="#Executor" class="headerlink" title="Executor"></a>Executor</h5><p>Java通过Executors提供四种线程池，分别为：</p>
<ul>
<li>newCachedThreadPool创建一个可缓存线程池，如果线程池长度超过处理需要，可灵活回收空闲线程，若无可回收，则新建线程。</li>
<li>newFixedThreadPool 创建一个定长线程池，可控制线程最大并发数，超出的线程会在队列中等待。</li>
<li>newScheduledThreadPool 创建一个定长线程池，支持定时及周期性任务执行。</li>
<li>newSingleThreadExecutor 创建一个单线程化的线程池，它只会用唯一的工作线程来执行任务，保证所有任务按照指定顺序(FIFO, LIFO, 优先级)执行。</li>
</ul>
<p>###### </p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> javacc.executor;</span><br><span class="line"></span><br><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@Auther</span>: chenv</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@Date</span>: 2018/11/5 09:47</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@Description</span>:</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">Threadv</span> <span class="keyword">implements</span> <span class="title">Runnable</span> </span>&#123;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">private</span> Integer index;</span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="title">Threadv</span><span class="params">(Integer index)</span></span>&#123;</span><br><span class="line">        <span class="keyword">this</span>.index=index;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@Override</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">run</span><span class="params">()</span> </span>&#123;</span><br><span class="line"></span><br><span class="line">        System.out.println(<span class="string">"执行业务。。。。。。"</span>);</span><br><span class="line"></span><br><span class="line">        <span class="keyword">try</span>&#123;</span><br><span class="line">            System.out.println(<span class="string">"开始执行线程。。。"</span>);</span><br><span class="line">            Thread.sleep(index*<span class="number">100</span>);</span><br><span class="line">            System.out.println(<span class="string">"我的线程数是： "</span>+<span class="keyword">this</span>.toString() +<span class="string">" index :"</span>+index);</span><br><span class="line">        &#125;<span class="keyword">catch</span> (Exception e)&#123;</span><br><span class="line">            e.printStackTrace();</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h6 id="newCachedThreadPool"><a href="#newCachedThreadPool" class="headerlink" title="newCachedThreadPool"></a>newCachedThreadPool</h6><p>创建一个可缓存线程池，应用中存在的线程数可以无限大</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> *  可缓存线程池，应用中存在的线程数可以无限大</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line">ExecutorService newCachedThreadPool = Executors.newCachedThreadPool();</span><br><span class="line">System.out.println(<span class="string">"********************newCachedThreadPool********************"</span>);</span><br><span class="line"><span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i &lt; <span class="number">10</span>; i++) &#123;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">final</span> <span class="keyword">int</span> index = i;</span><br><span class="line">    newCachedThreadPool.execute(<span class="keyword">new</span> Threadv(index));</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>输出：<br><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br></pre></td><td class="code"><pre><span class="line">********************newCachedThreadPool********************</span><br><span class="line">执行业务。。。。。。</span><br><span class="line">开始执行线程。。。</span><br><span class="line">执行业务。。。。。。</span><br><span class="line">开始执行线程。。。</span><br><span class="line">执行业务。。。。。。</span><br><span class="line">开始执行线程。。。</span><br><span class="line">执行业务。。。。。。</span><br><span class="line">开始执行线程。。。</span><br><span class="line">我的线程数是： javacc.executor.Threadv@<span class="number">1478</span>a613 index :<span class="number">0</span></span><br><span class="line">执行业务。。。。。。</span><br><span class="line">开始执行线程。。。</span><br><span class="line">执行业务。。。。。。</span><br><span class="line">开始执行线程。。。</span><br><span class="line">执行业务。。。。。。</span><br><span class="line">开始执行线程。。。</span><br><span class="line">执行业务。。。。。。</span><br><span class="line">开始执行线程。。。</span><br><span class="line">执行业务。。。。。。</span><br><span class="line">开始执行线程。。。</span><br><span class="line">执行业务。。。。。。</span><br><span class="line">开始执行线程。。。</span><br><span class="line">我的线程数是： javacc.executor.Threadv@<span class="number">42</span>ab3a06 index :<span class="number">1</span></span><br><span class="line">我的线程数是： javacc.executor.Threadv@<span class="number">51e03</span>dd8 index :<span class="number">2</span></span><br><span class="line">我的线程数是： javacc.executor.Threadv@<span class="number">4e3058f</span>8 index :<span class="number">3</span></span><br><span class="line">我的线程数是： javacc.executor.Threadv@<span class="number">76f</span>e9cc2 index :<span class="number">4</span></span><br><span class="line">我的线程数是： javacc.executor.Threadv@<span class="number">1f</span>7a85de index :<span class="number">5</span></span><br><span class="line">我的线程数是： javacc.executor.Threadv@<span class="number">1</span>aff604b index :<span class="number">6</span></span><br><span class="line">我的线程数是： javacc.executor.Threadv@<span class="number">495</span>beecb index :<span class="number">7</span></span><br><span class="line">我的线程数是： javacc.executor.Threadv@<span class="number">77767</span>c58 index :<span class="number">8</span></span><br><span class="line">我的线程数是： javacc.executor.Threadv@<span class="number">5259e47</span>e index :<span class="number">9</span></span><br></pre></td></tr></table></figure></p>
<h6 id="newFixedThreadPool"><a href="#newFixedThreadPool" class="headerlink" title="newFixedThreadPool"></a>newFixedThreadPool</h6><p>创建一个定长线程池，可控制线程最大并发数，超出的线程会在队列中等待。</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 定长线程池，可控制线程最大并发数，超出的线程会在队列中等待</span></span><br><span class="line"><span class="comment">//线程池允许同时存在两个线程</span></span><br><span class="line">ExecutorService newFixedThreadPool = Executors.newFixedThreadPool(<span class="number">2</span>);</span><br><span class="line">System.out.println(<span class="string">"****************************newFixedThreadPool*******************************"</span>);</span><br><span class="line"><span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">0</span>;i&lt;<span class="number">10</span>;i++)</span><br><span class="line">&#123;</span><br><span class="line">    <span class="keyword">final</span> <span class="keyword">int</span> index=i;</span><br><span class="line">    newFixedThreadPool.execute(<span class="keyword">new</span> Threadv(index));</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>输出 ：</p>
<p>每次只有俩个线程存在<br><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br></pre></td><td class="code"><pre><span class="line">****************************newFixedThreadPool*******************************</span><br><span class="line">执行业务。。。。。。</span><br><span class="line">开始执行线程。。。</span><br><span class="line">执行业务。。。。。。</span><br><span class="line">开始执行线程。。。</span><br><span class="line">我的线程数是： javacc.executor.Threadv@<span class="number">4f</span>044f6c index :<span class="number">0</span></span><br><span class="line">执行业务。。。。。。</span><br><span class="line">开始执行线程。。。</span><br><span class="line">我的线程数是： javacc.executor.Threadv@<span class="number">4</span>bb881c1 index :<span class="number">1</span></span><br><span class="line">执行业务。。。。。。</span><br><span class="line">开始执行线程。。。</span><br><span class="line">我的线程数是： javacc.executor.Threadv@<span class="number">41</span>c3a8fc index :<span class="number">2</span></span><br><span class="line">执行业务。。。。。。</span><br><span class="line">开始执行线程。。。</span><br><span class="line">我的线程数是： javacc.executor.Threadv@<span class="number">457f</span>66c6 index :<span class="number">3</span></span><br><span class="line">执行业务。。。。。。</span><br><span class="line">开始执行线程。。。</span><br><span class="line">我的线程数是： javacc.executor.Threadv@<span class="number">45f</span>c241c index :<span class="number">4</span></span><br><span class="line">执行业务。。。。。。</span><br><span class="line">开始执行线程。。。</span><br><span class="line">我的线程数是： javacc.executor.Threadv@<span class="number">4140</span>eab1 index :<span class="number">5</span></span><br><span class="line">执行业务。。。。。。</span><br><span class="line">开始执行线程。。。</span><br><span class="line">我的线程数是： javacc.executor.Threadv<span class="meta">@fea</span>2c7 index :<span class="number">6</span></span><br><span class="line">执行业务。。。。。。</span><br><span class="line">开始执行线程。。。</span><br><span class="line">我的线程数是： javacc.executor.Threadv@<span class="number">4426</span>cfd index :<span class="number">7</span></span><br><span class="line">执行业务。。。。。。</span><br><span class="line">开始执行线程。。。</span><br><span class="line">我的线程数是： javacc.executor.Threadv@<span class="number">6</span>d6cf29b index :<span class="number">8</span></span><br><span class="line">我的线程数是： javacc.executor.Threadv<span class="meta">@bfb</span>533d index :<span class="number">9</span></span><br></pre></td></tr></table></figure></p>
<h6 id="newScheduledThreadPool"><a href="#newScheduledThreadPool" class="headerlink" title="newScheduledThreadPool"></a>newScheduledThreadPool</h6><p>创建一个定长线程池，支持定时及周期性任务执行</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 定长线程池，支持定时及周期性任务执行</span></span><br><span class="line">ScheduledExecutorService newScheduledThreadPool = Executors.newScheduledThreadPool(<span class="number">2</span>);</span><br><span class="line">System.out.println(<span class="string">"****************************newScheduledThreadPool*******************************"</span>);</span><br><span class="line"><span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">0</span>;i&lt;<span class="number">10</span>;i++)</span><br><span class="line">&#123;</span><br><span class="line">    <span class="keyword">final</span> <span class="keyword">int</span> index=i;</span><br><span class="line">    <span class="comment">//延迟三秒执行</span></span><br><span class="line">    newScheduledThreadPool.schedule(<span class="keyword">new</span> Threadv(index),<span class="number">3</span>, TimeUnit.SECONDS);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>输出 ：</p>
<p>==延迟三秒之后执行，除了延迟执行之外和newFixedThreadPool基本相同，可以用来执行定时任务==<br><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br></pre></td><td class="code"><pre><span class="line">****************************newScheduledThreadPool*******************************</span><br><span class="line">执行业务。。。。。。</span><br><span class="line">开始执行线程。。。</span><br><span class="line">我的线程数是： javacc.executor.Threadv@<span class="number">52</span>a91127 index :<span class="number">0</span></span><br><span class="line">执行业务。。。。。。</span><br><span class="line">执行业务。。。。。。</span><br><span class="line">开始执行线程。。。</span><br><span class="line">开始执行线程。。。</span><br><span class="line">我的线程数是： javacc.executor.Threadv@<span class="number">56969f</span>aa index :<span class="number">1</span></span><br><span class="line">执行业务。。。。。。</span><br><span class="line">开始执行线程。。。</span><br><span class="line">我的线程数是： javacc.executor.Threadv@<span class="number">6</span>c7d6e81 index :<span class="number">2</span></span><br><span class="line">执行业务。。。。。。</span><br><span class="line">开始执行线程。。。</span><br><span class="line">我的线程数是： javacc.executor.Threadv@<span class="number">13941</span>b1c index :<span class="number">3</span></span><br><span class="line">执行业务。。。。。。</span><br><span class="line">开始执行线程。。。</span><br><span class="line">我的线程数是： javacc.executor.Threadv@<span class="number">62</span>ba8d7e index :<span class="number">4</span></span><br><span class="line">执行业务。。。。。。</span><br><span class="line">开始执行线程。。。</span><br><span class="line">我的线程数是： javacc.executor.Threadv@<span class="number">38f</span>7f590 index :<span class="number">5</span></span><br><span class="line">执行业务。。。。。。</span><br><span class="line">开始执行线程。。。</span><br><span class="line">我的线程数是： javacc.executor.Threadv@<span class="number">668505f</span>1 index :<span class="number">6</span></span><br><span class="line">执行业务。。。。。。</span><br><span class="line">开始执行线程。。。</span><br><span class="line">我的线程数是： javacc.executor.Threadv@<span class="number">22</span>cdeb80 index :<span class="number">7</span></span><br><span class="line">执行业务。。。。。。</span><br><span class="line">开始执行线程。。。</span><br><span class="line">我的线程数是： javacc.executor.Threadv@<span class="number">23878745</span> index :<span class="number">8</span></span><br><span class="line">我的线程数是： javacc.executor.Threadv@<span class="number">40445</span>bbc index :<span class="number">9</span></span><br></pre></td></tr></table></figure></p>
<h6 id="newSingleThreadExecutor"><a href="#newSingleThreadExecutor" class="headerlink" title="newSingleThreadExecutor"></a>newSingleThreadExecutor</h6><p>创建一个单线程化的线程池，它只会用唯一的工作线程来执行任务，保证所有任务按照指定顺序(FIFO, LIFO, 优先级)执行<br><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//单线程化的线程池，它只会用唯一的工作线程来执行任务，保证所有任务按照指定顺序(FIFO, LIFO, 优先级)执行</span></span><br><span class="line"></span><br><span class="line"> ExecutorService newSingleThreadExecutor = Executors.newSingleThreadExecutor();</span><br><span class="line"> System.out.println(<span class="string">"****************************newSingleThreadExecutor*******************************"</span>);</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">0</span>;i&lt;<span class="number">10</span>;i++)</span><br><span class="line"> &#123;</span><br><span class="line">     <span class="keyword">final</span> <span class="keyword">int</span> index=i;</span><br><span class="line">     newSingleThreadExecutor.execute(<span class="keyword">new</span> Threadv(index));</span><br><span class="line"> &#125;</span><br></pre></td></tr></table></figure></p>
<p>输出 ：<br><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br></pre></td><td class="code"><pre><span class="line">****************************newSingleThreadExecutor*******************************</span><br><span class="line">执行业务。。。。。。</span><br><span class="line">开始执行线程。。。</span><br><span class="line">我的线程数是： javacc.executor.Threadv@<span class="number">342648</span>c8 index :<span class="number">0</span></span><br><span class="line">执行业务。。。。。。</span><br><span class="line">开始执行线程。。。</span><br><span class="line">我的线程数是： javacc.executor.Threadv@<span class="number">3</span>ae1a03c index :<span class="number">1</span></span><br><span class="line">执行业务。。。。。。</span><br><span class="line">开始执行线程。。。</span><br><span class="line">我的线程数是： javacc.executor.Threadv@<span class="number">3</span>ede23b8 index :<span class="number">2</span></span><br><span class="line">执行业务。。。。。。</span><br><span class="line">开始执行线程。。。</span><br><span class="line">我的线程数是： javacc.executor.Threadv@<span class="number">7</span>bdcaa07 index :<span class="number">3</span></span><br><span class="line">执行业务。。。。。。</span><br><span class="line">开始执行线程。。。</span><br><span class="line">我的线程数是： javacc.executor.Threadv@<span class="number">7</span>d3acdbc index :<span class="number">4</span></span><br><span class="line">执行业务。。。。。。</span><br><span class="line">开始执行线程。。。</span><br><span class="line">我的线程数是： javacc.executor.Threadv@<span class="number">4</span>aed7267 index :<span class="number">5</span></span><br><span class="line">执行业务。。。。。。</span><br><span class="line">开始执行线程。。。</span><br><span class="line">我的线程数是： javacc.executor.Threadv@<span class="number">5e14</span>b61 index :<span class="number">6</span></span><br><span class="line">执行业务。。。。。。</span><br><span class="line">开始执行线程。。。</span><br><span class="line">我的线程数是： javacc.executor.Threadv@<span class="number">1</span>bf35548 index :<span class="number">7</span></span><br><span class="line">执行业务。。。。。。</span><br><span class="line">开始执行线程。。。</span><br><span class="line">我的线程数是： javacc.executor.Threadv@<span class="number">308f</span>3ca7 index :<span class="number">8</span></span><br><span class="line">执行业务。。。。。。</span><br><span class="line">开始执行线程。。。</span><br><span class="line">我的线程数是： javacc.executor.Threadv@<span class="number">11501e9</span>b index :<span class="number">9</span></span><br></pre></td></tr></table></figure></p>

      
    </div>
    <footer class="article-footer">
      <a data-url="http://yoursite.com/2018/11/05/Exceutor/" data-id="ckcc5iwie0005q4uwsbgjuqyh" class="article-share-link">Teilen</a>
      
      
  <ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/线程/">线程</a></li></ul>

    </footer>
  </div>
  
</article>


  
    <article id="post-测试" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-meta">
    <a href="/2018/11/03/测试/" class="article-date">
  <time datetime="2018-11-03T13:36:56.000Z" itemprop="datePublished">2018-11-03</time>
</a>
    
  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 itemprop="name">
      <a class="article-title" href="/2018/11/03/测试/">Spring boot test</a>
    </h1>
  

      </header>
    
    <div class="article-entry" itemprop="articleBody">
      
        <h5 id="Spring-boot-test"><a href="#Spring-boot-test" class="headerlink" title="Spring boot test"></a>Spring boot test</h5><ul>
<li>pom</li>
</ul>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line">     <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>org.springframework.boot<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">     <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>spring-boot-starter-test<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line">     <span class="tag">&lt;<span class="name">scope</span>&gt;</span>test<span class="tag">&lt;/<span class="name">scope</span>&gt;</span></span><br><span class="line">     <span class="comment">&lt;!--&lt;version&gt;1.4.3.RELEASE&lt;/version&gt;--&gt;</span></span><br><span class="line"> <span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br></pre></td></tr></table></figure>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line"><span class="meta">@SpringBootApplication</span> </span><br><span class="line">    <span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">StartUpApplication</span> </span>&#123; </span><br><span class="line">        <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">main</span><span class="params">(String[] args)</span> </span>&#123;    </span><br><span class="line">            SpringApplication.run(StartUpApplication.class, args);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>controller</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line"><span class="meta">@RequestMapping</span>(value = <span class="string">"/get_Str2"</span>,method = RequestMethod.GET)</span><br><span class="line"><span class="meta">@ApiOperation</span>(value = <span class="string">"get_Str"</span>)</span><br><span class="line"><span class="meta">@ResponseBody</span></span><br><span class="line"><span class="function"><span class="keyword">public</span> BaseResponse <span class="title">getStr2</span><span class="params">()</span></span>&#123;</span><br><span class="line"></span><br><span class="line">    BaseResponse response = <span class="keyword">new</span> BaseResponse();</span><br><span class="line">    String str = <span class="string">"helllo spring str2"</span>;</span><br><span class="line">    String str2 = <span class="string">"helllo spring str2"</span>;</span><br><span class="line">    response.setStr(str +str2);</span><br><span class="line">    <span class="keyword">return</span> response;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>test</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@RunWith</span>(SpringRunner.class)</span><br><span class="line"><span class="meta">@SpringBootTest</span>(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)</span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">CacheTest</span> </span>&#123;</span><br><span class="line">    </span><br><span class="line">    <span class="meta">@Test</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">testCache</span><span class="params">()</span><span class="keyword">throws</span> Exception</span>&#123;</span><br><span class="line">        </span><br><span class="line">        <span class="comment">//...</span></span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>test(moc)</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@RunWith</span>(SpringRunner.class)</span><br><span class="line"><span class="meta">@AutoConfigureMockMvc</span> <span class="comment">//mockmvc</span></span><br><span class="line"><span class="meta">@SpringBootTest</span>(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)</span><br><span class="line"><span class="meta">@ComponentScan</span>(&#123;<span class="string">"com.test.xxx.xxx"</span>,<span class="string">"com.test.xxx.xxx.impl"</span>&#125;)</span><br><span class="line"><span class="meta">@EntityScan</span>(&#123;<span class="string">"com.tes.xxx.entity"</span>,<span class="string">"com.xxx.xxx.entity"</span>&#125;)</span><br><span class="line"><span class="meta">@Rollback</span></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">CacheTest</span> </span>&#123;</span><br><span class="line">    </span><br><span class="line">    <span class="meta">@Autowired</span></span><br><span class="line">    MockMvc mockMvc;</span><br><span class="line">    </span><br><span class="line">    <span class="meta">@Test</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">testCache</span><span class="params">()</span><span class="keyword">throws</span> Exception</span>&#123;</span><br><span class="line">        </span><br><span class="line">        MvcResult result=mockMvc.perform(MockMvcRequestBuilders.get(<span class="string">"/simplecms/test.action"</span>)).andDo(MockMvcResultHandlers.print()).andReturn();</span><br><span class="line">        </span><br><span class="line">        String respStr=result.getResponse().getContentAsString();</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
      
    </div>
    <footer class="article-footer">
      <a data-url="http://yoursite.com/2018/11/03/测试/" data-id="ckcc5iwma004rq4uwksnycfnz" class="article-share-link">Teilen</a>
      
      
  <ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/springboot/">springboot</a></li></ul>

    </footer>
  </div>
  
</article>


  


  <nav id="page-nav">
    
    <a class="extend prev" rel="prev" href="/page/5/">&laquo; zurück</a><a class="page-number" href="/">1</a><span class="space">&hellip;</span><a class="page-number" href="/page/4/">4</a><a class="page-number" href="/page/5/">5</a><span class="page-number current">6</span><a class="page-number" href="/page/7/">7</a><a class="page-number" href="/page/8/">8</a><span class="space">&hellip;</span><a class="page-number" href="/page/15/">15</a><a class="extend next" rel="next" href="/page/7/">weiter &raquo;</a>
  </nav>

</section>
        
          <aside id="sidebar">
  
    

  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Tags</h3>
    <div class="widget">
      <ul class="tag-list"><li class="tag-list-item"><a class="tag-list-link" href="/tags/Design-Patterns/">Design Patterns</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Git/">Git</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Html/">Html</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Http/">Http</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/JavaScript/">JavaScript</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Sort/">Sort</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/algorithm/">algorithm</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/ali-weixin-pay/">ali/weixin pay</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/docker/">docker</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/elasticsearch/">elasticsearch</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/go/">go</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/hexo/">hexo</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/idea/">idea</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/java/">java</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/jvm/">jvm</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/linux/">linux</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/logstash/">logstash</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/mysql/">mysql</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/php/">php</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/pytest/">pytest</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/python/">python</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/springboot/">springboot</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/util/">util</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/vue/">vue</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/wechat/">wechat</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/我的世界/">我的世界</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/消息队列/">消息队列</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/线程/">线程</a></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Tag Cloud</h3>
    <div class="widget tagcloud">
      <a href="/tags/Design-Patterns/" style="font-size: 16.36px;">Design Patterns</a> <a href="/tags/Git/" style="font-size: 10px;">Git</a> <a href="/tags/Html/" style="font-size: 10px;">Html</a> <a href="/tags/Http/" style="font-size: 12.73px;">Http</a> <a href="/tags/JavaScript/" style="font-size: 15.45px;">JavaScript</a> <a href="/tags/Sort/" style="font-size: 18.18px;">Sort</a> <a href="/tags/algorithm/" style="font-size: 11.82px;">algorithm</a> <a href="/tags/ali-weixin-pay/" style="font-size: 13.64px;">ali/weixin pay</a> <a href="/tags/docker/" style="font-size: 17.27px;">docker</a> <a href="/tags/elasticsearch/" style="font-size: 10px;">elasticsearch</a> <a href="/tags/go/" style="font-size: 11.82px;">go</a> <a href="/tags/hexo/" style="font-size: 10px;">hexo</a> <a href="/tags/idea/" style="font-size: 10px;">idea</a> <a href="/tags/java/" style="font-size: 20px;">java</a> <a href="/tags/jvm/" style="font-size: 11.82px;">jvm</a> <a href="/tags/linux/" style="font-size: 18.18px;">linux</a> <a href="/tags/logstash/" style="font-size: 12.73px;">logstash</a> <a href="/tags/mysql/" style="font-size: 14.55px;">mysql</a> <a href="/tags/php/" style="font-size: 11.82px;">php</a> <a href="/tags/pytest/" style="font-size: 10px;">pytest</a> <a href="/tags/python/" style="font-size: 13.64px;">python</a> <a href="/tags/springboot/" style="font-size: 17.27px;">springboot</a> <a href="/tags/util/" style="font-size: 19.09px;">util</a> <a href="/tags/vue/" style="font-size: 10px;">vue</a> <a href="/tags/wechat/" style="font-size: 10.91px;">wechat</a> <a href="/tags/我的世界/" style="font-size: 10px;">我的世界</a> <a href="/tags/消息队列/" style="font-size: 10.91px;">消息队列</a> <a href="/tags/线程/" style="font-size: 11.82px;">线程</a>
    </div>
  </div>

  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Archiv</h3>
    <div class="widget">
      <ul class="archive-list"><li class="archive-list-item"><a class="archive-list-link" href="/archives/2020/05/">May 2020</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2020/04/">April 2020</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2020/03/">March 2020</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2020/01/">January 2020</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/10/">October 2019</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/08/">August 2019</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/06/">June 2019</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/04/">April 2019</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/03/">March 2019</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/02/">February 2019</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/01/">January 2019</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2018/12/">December 2018</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2018/11/">November 2018</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2018/10/">October 2018</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2018/09/">September 2018</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2018/07/">July 2018</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2018/06/">June 2018</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2018/05/">May 2018</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2018/04/">April 2018</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2018/03/">March 2018</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2018/02/">February 2018</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2018/01/">January 2018</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/12/">December 2017</a></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">letzter Beitrag</h3>
    <div class="widget">
      <ul>
        
          <li>
            <a href="/2020/05/17/linux/linux_shell/">linux—shell</a>
          </li>
        
          <li>
            <a href="/2020/05/16/linux/linux_awk_sed/">linux-awk\sed 示例</a>
          </li>
        
          <li>
            <a href="/2020/04/11/linux/linux_bash/">linux—bash</a>
          </li>
        
          <li>
            <a href="/2020/03/29/hello-world/">Hello World</a>
          </li>
        
          <li>
            <a href="/2020/03/16/go基础/">go基础知识</a>
          </li>
        
      </ul>
    </div>
  </div>

  
</aside>
        
      </div>
      <footer id="footer">
  
  <div class="outer">
    <div id="footer-info" class="inner">
      &copy; 2020 vchen<br>
      Powered by <a href="http://hexo.io/" target="_blank">Hexo</a>
    </div>
  </div>
</footer>
    </div>
    <nav id="mobile-nav">
  
    <a href="/" class="mobile-nav-link">Home</a>
  
    <a href="/archives" class="mobile-nav-link">Archives</a>
  
</nav>
    

<script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>


  <link rel="stylesheet" href="/fancybox/jquery.fancybox.css">
  <script src="/fancybox/jquery.fancybox.pack.js"></script>


<script src="/js/script.js"></script>



  </div>
</body>
</html>